我无法修改由 ng-repeat 生成的文本框。由于父/子范围,它也有点复杂。
链接:http: //jsfiddle.net/tzXn2/
剧本:
function ConfigController($scope)
{
$scope.config = {"key1":["a","b","c"]};
}
function SettingController($scope)
{
var configKey = null;
function update() {
$scope.items = $scope.config[configKey];
}
$scope.init = function(key) {
configKey = key;
update();
};
$scope.$watch('config', update, true);
}
标记:
<div ng-app ng-controller="ConfigController">
Config: {{config}}
<div ng-controller="SettingController" ng-init="init('key1')">
Items: {{items}}
<div ng-repeat="item in items">
<input ng-model="item" type="text"/>
</div>
</div>
</div>