angularjs empty selection on dropdown menu -
i stumbled upon problem angularjs. started learning recently, came upon issue. found few people same problem, executed coding differently me part. so, able put together. in case, trying do: in form, dropdown menu automatically chooses first option, blank reason (something angularjs default protection or something).
before trying code below, code far had been working correctly. now, last section of form, stars illustrated below, opened, no matter when in fact should opened when asked. furthermore, because of faulty coding, section not work (because of faulty coding). believe correcting main problem in code below, minor problems going fix in process.
anyhow, html (followed js portion) below:
<blockquote ng-repeat="review in product.reviews"> <b>stars: {{select.stars}}</b> {{review.body}} <cite>by: {{review.author}}</cite> </blockquote> <form name="reviewform"> <blockquote> <b> stars: {{select.stars}}</b> <br/> <b> review: {{review.body}}</b> <br/> <cite>by: {{review.author}}</cite> </blockquote> <!--<select ng-controller="starscontroller" ng-model="review.stars" name="stars" id="stars" style="margin-bottom:10px;margin-left:36px;width:350px;">--> <select ng-controller="starscontroller" ng-model="select" name="stars" id="stars" ng-options="option.name option in typeoptions"> <optgroup label="rate product"> <option value="1 star" name="1 star">1 star</option> <option value="2 stars" name="2 stars">2 stars</option> <option value="3 stars" name="3 stars">3 stars</option> <option value="4 stars" name="4 stars">4 stars</option> <option value="5 stars" name="5 stars" selected="selected">5 stars</option> </optgroup> </select>
js
app.controller("starscontroller", function myctrl($scope) { $scope.typeoptions = [ { name: '1 star', value: '1 star' }, { name: '2 stars', value: '2 stars' }, { name: '3 stars', value: '3 stars' }, { name: '4 stars', value: '4 stars' }, { name: '5 stars', value: '5 stars' } ]; $scope.select = $scope.typeoptions[4]; } );
i this:
html:
<select ng-model="select" ng-options="option.name option in typeoptions"></select>
js:
$scope.typeoptions = [ { name: '1 star', value: '1 star' }, { name: '2 stars', value: '2 stars' }, { name: '3 stars', value: '3 stars' }, { name: '4 stars', value: '4 stars' }, { name: '5 stars', value: '5 stars' } ]; $scope.select = $scope.typeoptions[4];
Comments
Post a Comment