javascript - AngularJS Simple ng-switch not working -
no error visible. wrong ng-switch directive or i've issue somewhere else ?
controller
app.controller("myctrl", ["$scope", function($scope) { $scope.model.error = 1; }]); view
<div ng-switch="model.error"> <label ng-switch-when="1">error: username not exists.</label> <label ng-switch-when="2">error: password incorrect.</label> <label ng-switch-when="3">error: username taken.</label> </div>
there nil wrong ngswitch. problem not initializing variable $scope.model hence must getting error in browser console.
typeerror: cannot set property 'error' of undefined use
app.controller('mainctrl', function($scope) { $scope.model = {}; //added line initializing variable. $scope.model.error = 1; }); demo
javascript angularjs
No comments:
Post a Comment