在 angular ng-options 中更改范围
change scope in angular ng-options
angular、
的新手
我有这个:
<div ng-controller="Ctrl">
Sort by:
<select ng-model="voterList" ng-options="voter as voter.name for voter in voter.availableOptions">
</select>
<p>Ordered by: {{voterList.name}}</p>
和
var app = angular.module('app', []);
function Ctrl($scope) {
$scope.voter = {
availableOptions: [
{id: '1', name: 'Option A'},
{id: '2', name: 'Option B'},
{id: '3', name: 'Option C'}
],
};
}
我需要将 $scope 更改为 $scope.voter.DoNotContactBefore
而不是 $scope.voter
但这似乎与 ng-options 混淆了。我不知道我需要改变什么。
非常感谢帮助,谢谢!
不确定我是否正确理解了你的问题,但我感觉你只需要重写:
$scope.voter = {
availableOptions: [
{id: '1', name: 'Option A'},
{id: '2', name: 'Option B'},
{id: '3', name: 'Option C'}
],
};
至:
$scope.voter = {
DoNotContactBefore: {
availableOptions: [
{id: '1', name: 'Option A'},
{id: '2', name: 'Option B'},
{id: '3', name: 'Option C'}
]
}
};
然后只需将 "ng-options" 更改为 ng-options="voter as voter.name for voter in voter.DoNotContactBefore.availableOptions"
angular、
的新手我有这个:
<div ng-controller="Ctrl">
Sort by:
<select ng-model="voterList" ng-options="voter as voter.name for voter in voter.availableOptions">
</select>
<p>Ordered by: {{voterList.name}}</p>
和
var app = angular.module('app', []);
function Ctrl($scope) {
$scope.voter = {
availableOptions: [
{id: '1', name: 'Option A'},
{id: '2', name: 'Option B'},
{id: '3', name: 'Option C'}
],
};
}
我需要将 $scope 更改为 $scope.voter.DoNotContactBefore
而不是 $scope.voter
但这似乎与 ng-options 混淆了。我不知道我需要改变什么。
非常感谢帮助,谢谢!
不确定我是否正确理解了你的问题,但我感觉你只需要重写:
$scope.voter = {
availableOptions: [
{id: '1', name: 'Option A'},
{id: '2', name: 'Option B'},
{id: '3', name: 'Option C'}
],
};
至:
$scope.voter = {
DoNotContactBefore: {
availableOptions: [
{id: '1', name: 'Option A'},
{id: '2', name: 'Option B'},
{id: '3', name: 'Option C'}
]
}
};
然后只需将 "ng-options" 更改为 ng-options="voter as voter.name for voter in voter.DoNotContactBefore.availableOptions"