myModule.controller('MetadataController', function () {
this.allOrganisations = [{name:"test"}, {name:"alpha"}, {name:"beta"}];
var arrayLength = this.allOrganisations.length;
for (var i = 0; i < arrayLength; i++) {
alert(this.allOrganisations[i].name);
}
});
正在运作,但在视图中什么都没有出来?
<form name="form" novalidate ng-controller="MetadataController" class="form-inline">
<select ng-model="form.metadata.title.organisation" ng-options="organisation.name for organisation in form.AllOrganisations"></select><br>
<ul >
<li ng-repeat="o in form.allOrganisations">{{ o.name }}</li>
</ul>
答案 0 :(得分:0)
请参阅此处http://jsbin.com/wewiv/1/
myModule.controller('MetadataController', function ($scope) {
$scope.allOrganisations = [{name:"test"}, {name:"alpha"}, {name:"beta"}];
var arrayLength = $scope.allOrganisations.length;
for (var i = 0; i < arrayLength; i++) {
alert($scope.allOrganisations[i].name);
}
});
HTML:
<select ng-model="form.metadata.title.organisation" ng-options="organisation.name for organisation in allOrganisations"></select><br>
<ul >
<li ng-repeat="o in allOrganisations">{{ o.name }}</li>
</ul>
</div>