Javascript NGD型号don';上提深能级
当我有一个具有多个级别的ngModel,并且在范围中以编程方式修改该值时,该值不会在UI中更新。如果我把一块美元的手表放在同一块地产上,它就能工作。我怎样才能修复这个模型 html: 引导(文档,[app.name])Javascript NGD型号don';上提深能级,javascript,angularjs,Javascript,Angularjs,当我有一个具有多个级别的ngModel,并且在范围中以编程方式修改该值时,该值不会在UI中更新。如果我把一块美元的手表放在同一块地产上,它就能工作。我怎样才能修复这个模型 html: 引导(文档,[app.name]) 我想问题出在这条线路上 $scope.super = +value * 2; 您正在更改$scope.super的名称。所以你不能再使用$scope.super.s.s.s了 不过,我不明白你想要完成什么。也许是这样的 <form ng-controller="tes
我想问题出在这条线路上
$scope.super = +value * 2;
您正在更改$scope.super的名称。所以你不能再使用$scope.super.s.s.s了
不过,我不明白你想要完成什么。也许是这样的
<form ng-controller="testController">
<input type="text" ng-model="coco.c.c.c" />
<input type="text" ng-model="super.s.s.s" />
<input type="text" ng-model="super2" />
</form>
app.controller('testController', function ($scope) {
$scope.super = {s:{ s:{ }}}
$scope.coco = {
c: {
c: {
}
}
};
$scope.$watch('coco.c.c.c', function (value) {
$scope.super.s.s.s = +value * 2;
console.log("coco", value);
});
$scope.$watch('super.s.s.s', function (value) {
$scope.super2 = +value * 2;
console.log("super", value);
});
});
app.controller('testController',函数($scope){
$scope.super={s:{s:{}}
$scope.coco={
c:{
c:{
}
}
};
$scope.$watch('coco.c.c.c',函数(值){
$scope.super.s.s.s=+值*2;
console.log(“coco”,值);
});
$scope.$watch('super.s.s.s',函数(值){
$scope.super2=+值*2;
console.log(“超级”,值);
});
});
继续前面的答案。在线
$scope.super = +value * 2;
您正在将对象添加到一个数字,创建一个nan值,销毁模型引用,因此没有模型,因为对象是附加的,并通过引用监视。这意味着您的输入没有要监视的模型,因此您正在断开链
然后您尝试在控制器中侦听其他控制器范围中的更改??这是行不通的抱歉,您只能在您的范围内观察发生的事情您的ng模型中有一对多.c。你有coco.c.c.c,是不是应该是coco.c.c?不,我的ngModel是coco.c.c.c,我的手表是coco.c.c.c。手表被调用了,但是我的ngModel没有得到更新。我怀疑这是一个嵌套的范围问题。这里有一些信息:我理解您将ng模型和监视绑定到什么,但您的对象模型是$scope.coco.c.c,而不是coco.c.c。
<form ng-controller="testController">
<input type="text" ng-model="coco.c.c.c" />
<input type="text" ng-model="super.s.s.s" />
<input type="text" ng-model="super2" />
</form>
app.controller('testController', function ($scope) {
$scope.super = {s:{ s:{ }}}
$scope.coco = {
c: {
c: {
}
}
};
$scope.$watch('coco.c.c.c', function (value) {
$scope.super.s.s.s = +value * 2;
console.log("coco", value);
});
$scope.$watch('super.s.s.s', function (value) {
$scope.super2 = +value * 2;
console.log("super", value);
});
});
$scope.super = +value * 2;