我有项目列表
<ul>
<li><a>ItemA</a></li>
<li><a>ItemB{{vm.count}}</a></li>
</ul>
我正在准备控制器中的角度列表:
vm.listofItems =[{"textDisplay":"ItemA","Statego":""},
{"textDisplay":"ItemB{{vm.count}}","Statego":""}];
经过一些服务电话,我会得到vm.count值?现在如何绑定。
答案 0 :(得分:0)
好的,试试这段代码,首先我会建议你使用$ scope。我已经将countOfItems分配给了count计数,只要你改变$ scope.count的值,它就会适合你。
$scope.count;
$scope.$watch('count', function() {
$scope.listofItems =[
{"textDisplay":"ItemA","Statego":""},
{"textDisplay":"ItemB" +$scope.count,"Statego":""}
];
});
答案 1 :(得分:0)
在Html中
<div ng-app="app">
<div ng-controller="MainCtrl as main">
<ul>
<li ng-repeat='list in main.listofItems'>
<a href="">{{list.textDisplay}}</a>
</li>
</ul>
<input ng-model='main.count' ng-value='main.count'> {{main.count}}
</div>
</div>
在控制器中
var app = angular.module('app', []);
app.controller('MainCtrl', function($scope) {
var vm = this;
vm.count = 90;
vm.listofItems = [{
"textDisplay": "ItemA",
"Statego": ""
}, {
"textDisplay": "ItemB " + vm.count + "",
"Statego": ""
}];
$scope.$watch(angular.bind(this, function() {
return this.count;
}), function(newVal) {
vm.listofItems[1].textDisplay = "ItemB " + newVal;
// console.log(' change ' , newVal);
});
});
这是我想出的解决方案。这种方法是否正确?
jsFiddle for same:https://jsfiddle.net/nj5/ve4xmhtj/