0

The full source code.

I don't understand why $scope not working in my LoginGuideCtrl controller. I try click on login button and should show a <p> with new data but the $scope is not updating...

Don´t forget I'm trying to achieve a modular design.

I have the following code:

guides.js

var guides = angular.module('main.guides',  ['ui.router']).config(function ($stateProvider) {
  $stateProvider.
  state('guides.login', {
    url: '/login',
    templateUrl: 'modules/guides/views/login.html',
    controller: 'LoginGuideCtrl'
  }).

  ...

  state('guides.mobile', {
    url: '/web',
    template: '<div>guildes mobile</div>',
    controller: 'ListCtrl'
  });
});

controller.js

var guides = angular.module('main.guides');
guides.controller('IndexCtrl', function() {
    console.log('Index');
})
.controller('LoginGuideCtrl', function($scope) {

  console.log('feck');
  $scope.checkLogin = function(){
    $scope.message = "Welcome "+$scope.name+"!"
  };

})
.controller('ListCtrl', function() {
  console.log('List');
})

login.html

<div class="form-group col-sm-2">
  <label for="usr">Name:</label>
  <input type="text" class="form-control" id="usr" ng-model="name">
</div>
<div class="form-group col-sm-2">
  <label for="pwd">Password:</label>
  <input type="password" class="form-control" id="pwd" ng-model="password">
</div>
<button type="button" class="btn btn-default" ng-click="checkLogin()">Login</button>
<p ng-model="message"></p>
1
  • Can you expand on "$scope/controller not working"? That doesn't tell us much Commented Jan 22, 2016 at 1:20

1 Answer 1

1

ng-model is used with <input> tags to capture user input, by two way binding with your model value.

Since a <p> tag does not collect user input, it won't work with ng-model. Instead just do a one way binding with the value using the curly brackets:

<p>{{message}}</p>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.