angularjs - How can I handle isDirty in a component? -


i'm using angular 1.5 , creating custom drop-down. there no elements use ngmodel involved. want able have form know if component dirty, pristine, etc. thinking i'd use ngmodel, directive. however, since there no linking function in component, i'm not sure how this. possible?

let's component template this:

<div>{{model.value}}</div>

my code this:

angular.component('mything',  {     bindings: {         model: '='     },     require: '^ngmodel' }) .controller('mythingcontroller', () => {     // stuff , things }); 

i made simple example instead of of code because i'm not sure begin using ngmodel within component. didn't think served have me code dump. if more code required, please feel free ask , i'll happily expand example.

i created simple pen try work through this: http://codepen.io/yatrix/pen/rwejyv?editors=1011

you can use require: { ngmodel: '^ngmodel' } on component declaration. , can access through controller context, i.e., this.ngmodel within controller.

the following snippet implements example based on codepen.

var app = angular.module('app', []);    app.controller('ctrl', ($scope) => {    $scope.model = {      value: "hello"    };  });    app.component('mything', {    require: {      ngmodel: '^ngmodel'    },    template: '<div>{{$ctrl.ngmodel.value}}</div><br/><button type="button" ng-click="$ctrl.dosomething()">click this</button>',    bindings: {      ngmodel: '='    },    controller: function() {      this.dosomething = function() {        console.log(this.ngmodel);      }    }  });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.0/angular.js"></script>  <div ng-app="app" ng-controller="ctrl">      <my-thing ng-model="model"></my-thing>    </div>


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -