How to set a value to scope object.object in angularjs -
how set value , value in form of $scope.object1.object = "some data";
in html , js if set data work.
<select ng-model="mycolor" ng-options="color.name color in colors"> $scope.colors = [ {name:'black', shade:'dark'}, {name:'white', shade:'light'}, {name:'red', shade:'dark'}, {name:'blue', shade:'dark'}, {name:'yellow', shade:'light'} ];
but want these
<select ng-model="mycolor" ng-options="color.name color in test.colors"> $scope.test.colors = [ {name:'black', shade:'dark'}, {name:'white', shade:'light'}, {name:'red', shade:'dark'}, {name:'blue', shade:'dark'}, {name:'yellow', shade:'light'} ];
see example in plunker demo
see plunkr
angular.module('selectexample', []) .controller('examplecontroller', ['$scope', function($scope) { // add next line $scope.test = {} $scope.test.colors = [ {name:'black', shade:'dark'}, {name:'white', shade:'light'}, {name:'red', shade:'dark'}, {name:'blue', shade:'dark'}, {name:'yellow', shade:'light'} ]; $scope.mycolor = $scope.test.colors[2]; // red }]);
Comments
Post a Comment