javascript - AngularJS function not called in the controller -
it's hour i'm trying understand why function defined inside controller of angularjs project not being called.
app.js
angular.module('supplierportal', ['ngroute', 'ngresource']); userlogincontroller.js
angular.module('supplierportal').controller('userlogincontroller', function($scope, $location) { $scope.text = "hi"; $scope.login = function() { console.log('it doesn't show this'); $location.path(/admin); } }); login.html
<div class="container"> <div class="row"> <div class="col-sm-6 col-md-4 col-md-offset-4"> <div class="account-wall"> <img class="profile-img" src="https://lh5.googleusercontent.com/-b0-k99fzlye/aaaaaaaaaai/aaaaaaaaaaa/eu7opa4byxi/photo.jpg?sz=120" alt=""> <form class="form-signin"> <input type="text" class="form-control" placeholder="username" required autofocus> <input type="password" class="form-control" placeholder="password" required> <input class="btn btn-lg btn-primary btn-block" type="submit" ng-click="login()" value="login"> </form> </div> </div> </div> routes.js
angular.module('supplierportal').config(function($routeprovider) { $routeprovider .when("/", { templateurl: "assets/templates/users/login.html", controller: "userlogincontroller" }) .when("/admin/", { templateurl: "assets/templates/users/index_admin.html" }) .otherwise({ redirectto:'/' }); });
index.html
<!doctype html> <html ng-app="supplierportal"> <head> <meta charset="utf-8"> <title>login</title> <link rel="stylesheet" href="assets/styles/style.css"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css"> </head> <body> <div ng-view class="container"></div> <!-- scripts --> <!-- vendor --> <script src="assets/javascript/vendor/angular.min.js"></script> <script src="assets/javascript/vendor/angular-route.min.js"></script> <script src="assets/javascript/vendor/angular-resource.min.js"></script> <script src="assets/javascript/vendor/jquery-3.2.0.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <!-- app --> <script src="assets/javascript/app.js"></script> <script src="assets/javascript/routes.js"></script> <!-- controllers --> <script src="assets/javascript/controllers/users/userlogincontroller.js"></script> <!-- services --> <script src="assets/javascript/services/user.js"></script>
it not show text in console, , of course not go /admin/ path.
thanks try me!
fix following line:
console.log('it doesn't show this'); the string being closed "'" in middle of sentence, because used "doens't". either use " or dont use ' on "doens't" word
Comments
Post a Comment