【发布时间】:2014-04-15 19:55:50
【问题描述】:
所以我在事件发生后向 $scope 添加变量时遇到问题。 这是选择框的 HTML。基本上当它改变时,我需要改变范围。
Index.html
<select ng-controller="ClientCtrl" ng-model="name"
ng-options="v.name for (k, v) in client" ng-change="selectChange(name)">
</select>
<h2>{{cName}}</h2>
<p>Age: {{cAge}}</p>
<p>Notes: {{cNotes}}</p>
Controller.js
$scope.selectChange = function(name){
$scope.cName = name.name;
$scope.cAge = name.age;
$scope.cNotes = name.notes;
};
我已经尝试了一些方法来设置这些变量。显然是上面这个,然后是这个:
$scope.selectChange = function(name){
$scope.cName = name.name;
$scope.cAge = name.age;
$scope.cNotes = name.notes;
$scope.$apply();
};
我仍然不太了解 apply,但我想我会尝试一下。任何帮助都会很棒,只需要一个指针来解释为什么这不起作用。
我可以将变量发布到 console.log(cName);但是当我有 {{cName}}
时它不会显示【问题讨论】:
-
This was also an issue @StenMuchow 已回答。
标签: javascript angularjs