下面有一个模型对象“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;
但是它并没有按照我的预期工作。这是我的在线示例。
最佳答案
这不会起作用,因为它只是一个作业。试试这个:
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;
});
});
关于javascript - Angular 模型未针对对象的内部属性进行更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20926743/