AngularJS required attribute doesn't work on select -
i have next problem select in angularjs application. have set required attribute doesn't work on select tag. doesn't trigger native validation. here html code:
<div ng-app="app"> <div ng-controller="testctrl"> <form ng-submit="selectchanged()"> <select ng-model="first" required="required"> <option>choose</option> <option value="2">2</option> </select> <input type="submit" value="test"/> </form> </div> </div> here controller:
angular.module('app', []).controller('testctrl', function ($scope) { $scope.selectchanged = function () { }; }); here working jsfiddle: http://jsfiddle.net/zono/k3b5j/3/
best regards.
your code should be:
angular.module('app', []).controller('testctrl', function ($scope) { $scope.first = ""; $scope.selectchanged = function () { alert($scope.first); }; }); you didn't add together variable select bound to, $scope.first in case. , empty alternative should have value of "" --> <option value ="">choose</option>
here working fiddle: http://jsfiddle.net/k3b5j/4/
angularjs
No comments:
Post a Comment