I am trying to set the default value for the parameters. I am using select and ng-repeat. I get the data in a js file and I call the model to set the value there.
Please see below code:
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Example - example-ngrepeat-select-production</title> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.0-rc.2/angular.min.js"></script> <script src="app.js"></script> </head> <body ng-app="ngrepeatSelect"> <div ng-controller="ExampleController"> <form name="myForm"> <label for="repeatSelect"> Repeat select: </label> <select ng-model="datamodel"> <option ng-repeat="dataitem in data" ng-selected ="{{dataitem == datamodel}}">{{dataitem}}</option> </select> </form> <hr> <tt>repeatSelect = {{datamodel}}</tt><br/> </div> </body> </html>
App.js file
(function(angular) { 'use strict'; angular.module('ngrepeatSelect', []) .controller('ExampleController', ['$scope', function($scope) { $scope.data = [1,2,3,4,5]; $scope.datamodel = 2; }]); })(window.angular);
Here is my plunker
angularjs ng-repeat
Fhah
source share