angularjs - ng-click is not working in partial using ui-router -
i starting angularjs
, have routing issue ui-router
. have partial displays button sign in. issue clicking on button not call corresponding method in controller.
the module definition:
var myapp = angular.module('myapp', ['ui.state']); myapp.config(function($stateprovider, $routeprovider) { $stateprovider.state('signin', { url : "/", // root route views : { "signinview" : { templateurl : 'signin.html' } }, controller: function($scope) { $scope.auth = function() { console.log("clicked"); }; } //controller: 'logincontroller' }).state('signedin', { views : { "signinview" : { templateurl : 'partials/signedin.html' } } }); });
the signin.html
:
<button class="btn" ng-click="auth()">sign in</button>
plunker thats shows issue.
the controller definition should inside view definition.
code should this.
myapp.config(function($stateprovider, $routeprovider) { $stateprovider.state('signin', { url : "", // root route views : { "signinview" : { templateurl : 'signin.html', controller: function($scope) { $scope.auth = function() { alert("clicked"); console.log("clicked"); }; } } } //controller: 'logincontroller' }).state('signedin', { views : { "signinview" : { templateurl : 'partials/signedin.html' } } });
here plunker
Comments
Post a Comment