bound element inside ngIf does not update binding

前端 未结 3 977
滥情空心
滥情空心 2020-12-25 12:02

I have written a angularjs directive. in this directive\'s template I have added an ngIf directive and within it I display an input that is bound to my directive\'s scope.

3条回答
  •  萌比男神i
    2020-12-25 12:31

    Define foo as an object with properties. This all has to do with javascript prototypical inheritance. See your modified jsfiddle.

     angular.module('testApp', [])
      .controller('MyController',function($scope){
          $scope.foo = {bool: true};
      })
      .directive('testDir', function () {
        return {
          restrict: 'A',
          template: '

    changing me does not update the other inputs because i am in an ngIf if in ngShow all works just fine
    ', link: function (scope, elem, attrs) { scope.foo.x = "bar"; scope.foo.bool = true; } } });

    For a detailed info see this video.

提交回复
热议问题