没有为对象的内部属性更新角度模型

Dav*_*hen 2 javascript angularjs

我在下面有一个模型对象"o",它引用另一个范围属性testText.我希望当$ scope.testText更新时,$ scope.o.filed1会自动更新.

var app = angular.module('app', ['kendo.directives']); 
app.controller("myCtrl", function ($compile, $scope) {
$scope.o={};
$scope.testText = 'hello';
$scope.o.filed1 = $scope.testText;
Run Code Online (Sandbox Code Playgroud)

但它不像我预期的那样有效.这是我的在线样本.

http://plnkr.co/edit/ZHS8EdcCb5EJwQ8UUenj?p=preview

mic*_*ael 5

这不起作用,因为它只是一项任务.试试这个:

var app = angular.module('app', ['kendo.directives']); 

app.controller("myCtrl", function ($compile, $scope) {
   $scope.o={};
   $scope.testText = 'hello';
   $scope.$watch('testText', function(newValue){
      $scope.o.filed1 = newValue;
   });
});
Run Code Online (Sandbox Code Playgroud)