Karan Tiwari
Karan Tiwari

Reputation: 83

angularjs module and controller is not working

I'm trying to create module and controller for understanding the basic concept. I tried below code but it does not work.

<div ng-contoller = "MyController">
<p>
{{ author.name }}
</p>
<p>
{{ author.age }}
</p>
<p>
{{ author.sex }}
</p>
</div>

var myApp = angular.module('myApp',[]);


myApp.controller('MyController', function MyController($scope){
    $scope.author = {
        'name'  :   'Sameer Sashittal',
        'age'   :   '28',
        'sex'   :   'Male'
    }
});

Above code is not working. Can any one guide me where i'm doing wrong.

Upvotes: 3

Views: 220

Answers (2)

Hadi
Hadi

Reputation: 17289

Remove MyController. It should be like this.

  var myApp = angular.module('myApp',[]);
  myApp.controller('MyController', function($scope){
    $scope.author = {
      'name'  :   'Sameer Sashittal',
      'age'   :   '28',
      'sex'   :   'Male'
  }
});

Upvotes: 2

Sachila Ranawaka
Sachila Ranawaka

Reputation: 41387

add you module using ng-app to the div.

Also there is typo error in the ng-controller

<div ng-app="myApp" ng-controller = "MyController">

the controller should be

myApp.controller('MyController', function ($scope){

Upvotes: 2

Related Questions