3

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.

2 Answers 2

2

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){
Sign up to request clarification or add additional context in comments.

1 Comment

@Karan Tiwari nice make sure to check as answer if this helped :D
2

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

2 Comments

see also @sachila ranawaka answer.
I got it their was a typo error in <div ng-contoller = "MyController">

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.