I have a pretty strange problem. For some reason, my ng-model only bounds when I nest the same controller twice. Here is my code:
index page:
bbmean_app.controller('mainController', function($scope, $location, mainFactory){
$scope.test='hello';
$scope.currentUser = {};
$scope.login = function(){
console.log($scope.name)
}
<body>
<div ng-controller='mainController'>
<div ng-view =""></div>
</div>
</body>
view page:
<form>
{{test}}
<p>Your name:<input type = 'text' ng-model='name' ></p>
<button type = 'submit' ng-click ='login()'>Login</button>
</form>
so all my views should have a mainController as the controller and it shows 'hello' on the view page meaning it can display test(which implies connection to the controller) but when i click my submit button, the console log is undefined. it only works if my controller is recalled like this:
<div ng-controller = 'mainController'>
<form>
{{test}}
<p>Your name:<input type = 'text' ng-model='name' ></p>
<button type = 'submit' ng-click ='login()'>Login</button>
</form>
</div>
I have ng-app around my html and correct head tags in my codes as well. Any ideas?