Angularjs 从控制器中删除选项和阵列
我想在下拉列表中显示来自控制器的列表。数组是控制器变量,定义如下:Angularjs 从控制器中删除选项和阵列,angularjs,Angularjs,我想在下拉列表中显示来自控制器的列表。数组是控制器变量,定义如下: (function(angular) { 'use strict'; angular.module('staticSelect', []) .controller('ExampleController', ['$scope', function($scope) { self = this; self.options = [ {id: 1, label: "Item 1"},
(function(angular) {
'use strict';
angular.module('staticSelect', [])
.controller('ExampleController', ['$scope', function($scope) {
self = this;
self.options = [
{id: 1, label: "Item 1"},
{id: 2, label: "Item 2"},
{id: 3, label: "Item 3"}
];
$scope.data = {
singleSelect: null,
multipleSelect: [],
option1: 'option-1',
};
$scope.forceUnknownOption = function() {
$scope.data.singleSelect = 'nonsense';
};
}]);
})(window.angular);
现在,我想在下拉列表中显示这个选项数组。脚本如下:
单选:
selected={{data.singleSelect}}
如果选项数组位于
$scope
中,则此操作正常。我对AngularJS是新手。使用控制器变量时,我在这里做错了什么?以下是ng options属性的外观:
ng-options="option.id as option.label for option in ctrl.options"
以下是ng选项属性的外观:
ng-options="option.id as option.label for option in ctrl.options"