Wednesday, 15 August 2012

Adding conditional CSS classes with ng-class in AngularJS -



Adding conditional CSS classes with ng-class in AngularJS -

i have simple problem. want update classes within inputs on form submit.

<div class="form-group"> <input class="form-control" ng-class="{'has-error': signup.$submitted && signup.name.$invalid}" type="text" name="name" ng-model="formdata.name" required minlength="2" placeholder="full name"> </div>

here's app.js:

spinnrapp.controller('formcontroller', ['$scope', '$http', '$state', function (scope, http, state){ // list of cities , store select http.get('cities.json').success(function(data){ scope.cities = data; }) // store our form info in object scope.formdata = {}; // function process form scope.processform = function(isvalid) { scope.$submitted = true; if(isvalid && state.$current=='registration.spinnrapp') { state.go('registration.artist'); } else if(isvalid && state.$current=='registration.artist') { state.go('registration.share'); } else if(!isvalid && state.$current=='registration.artist') { alert('please create sure have selected artist.'); } else if(!isvalid && state.$current=='registration.spinnrapp') { return; } }; }]);

when execute submit via ng-click calling function, signup.$submitted still stays false. have reference plunker: http://plnkr.co/edit/xdizc0a50cxxmpihep3c?p=preview

that plunkr updates class. why isn't mine doing same? doing wrong?

css angularjs forms

No comments:

Post a Comment