AngularJS: read initial value of ngModel.$viewValue from different directive

后端 未结 4 1956
南笙
南笙 2021-01-03 08:44

I would like to read the initial value ngModel.$viewValue from different directive.

# coffee script
app.directive \'directive\', -> 
  return {
      requ         


        
4条回答
  •  遥遥无期
    2021-01-03 09:24

    No need to watch and ng-init is bad. Something like..

          return {
              require: 'ngModel',
              link: function(scope, element, attrs, ngModel) {
                    var getter = $parse(attrs.ngModel);
                    var value = getter(scope);
    
               }
            };
    

    Here value will give the initial bound value in model.

提交回复
热议问题