Angularjs module and controller not working

I am trying to create a module and controller to understand the basic concept. I've tried the code below but it doesn't 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'
    }
});

      

The above code doesn't work. Can anyone please direct me to where I am doing wrong.

+3


source to share


2 answers


add the module using ng-app

in div.

There is also a typo bug in ng-controller

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

      



controller should be

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

      

+2


source


Delete 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'
  }
});

      

+2


source







All Articles