0

I am a AngularJS beginer.Here is my HTML:

 <div class="col-md-12 footer" ng-controller="User">
  {{user.username||"ad"}}

 </div>

Here is my controllers.js:

angular.controller('User', user);
function User($scope){
    $scope.user={
        'username':"wang",
        'password':"wanghao"
    }
}

And I linked the controller in the (I am sure the link is right):

<script src="js/Angular/angular.js"></script>
      <script src="js/Angular/controllers.js"></script> 

But,when I run my code,here is the result:

{{user.username||"ad"}} 

Here is the error: enter image description here I am really confused.I tried to write the JS in the HTML,or link the Javascript before the controller.But it still didn't work!!

2
  • 1
    controller function name is User, not user. try it first. angular.controller('User', user); function User($scope){ $scope.user={ 'username':"wang", 'password':"wanghao" } } Commented Nov 13, 2015 at 4:17
  • Is this what you want jsfiddle.net/airwind711/e2onyhf5 Commented Nov 13, 2015 at 4:20

3 Answers 3

1

It's this part, capitalization on your function.

angular.controller('User', user);
function user($scope){
    $scope.user={
        'username':"wang",
        'password':"wanghao"
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

The function names are wrong in the controller and the function.

Just change it to function user($scope)

OR

You can declare your controller function directly like this:

angular.controller('User', function($scope){

});

Comments

0
 <div class="col-md-12 footer" ng-app="app" ng-controller="User">                
    {{user.username||"ad"}}
 </div>

 //---Controller---//
 var app = angular.module('app', []);
 app.controller('User', function($scope){
 $scope.user={
    'username':"wang",
    'password':"wanghao"
 }
 });

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.