简体   繁体   中英

Initializing an array javascript, angular controller

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);
        }
});

is working, but in the view nothing coming out ?

<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>

Please see here 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM