Inheritance for scopes in AngularJS

前端 未结 2 1303
遇见更好的自我
遇见更好的自我 2021-01-03 00:59

In a parent controller scope, I have defined selectedItem which is set to \'x\'. Then in the child scope, I have defined selectedItem using ngModel

2条回答
  •  没有蜡笔的小新
    2021-01-03 01:44

    I've noticed in similar cases that AngularJS does not watch selectedItem properly. The only way I found is to initialize selectedItem with an entry from the items array. Try the following:

    function CtrlA($scope) {
        $scope.items = ['x', 'y'];
        $scope.selectedItem = $scope.items[0];
    }
    

提交回复
热议问题