作为一个人为的例子,假设我有一个看起来像这样的角度控制器:
function OverflowController($scope) {
// initialize the count variable
$scope.count = 0;
// pretend the overflow logic is complex and doesn't belong in a filter or view
var count = parseInt($scope.count);
if (count < 100) {
$scope.overflow = "normal";
}
else if (count < 200) {
$scope.overflow = "warning";
}
else {
$scope.overflow = "error";
}
};
我有一个看起来像这样的视图:
<input ng-model="count">
<p>Count: {{count}}</p>
<p>Overflow? {{overflow}}</p>
如何将范围的溢出属性绑定到计数属性,以便在更新计数时,溢出也会自动更新?