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

后端 未结 4 1931
南笙
南笙 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:36

    put your actions within a $timeout... like what you do with $apply, so your code will run after $digest finished it's process...

    like this:

    link: function (scope, el, attr, ctrl) { //Ctrl will bind to required ones
                    //ctrl[0] -> ngModel
                    $timeout(function() {
                        scope.parentId = ctrl[0].$viewValue;
                        scope.startUp();
                    }, 0);
                }
    

提交回复
热议问题