1

I'm learning the AngularJS and was trying to do the basic thing which was:

<!doctype html>
<html ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"     type="text/javascript"></script>

<script type="text/javascript">
    var myapp = angular.module('MyTutorialApp',[]);

    myapp.controller("MyMainController", function($scope){
        $scope.understand = "I now understand how the scope works2!";
    });
</script>
</head>
<body ng-app='MyTutorialApp'>
    <div id='content' ng-controller='MyMainController'>
        {{understand}}
    </div>
</body>
</html>

But I'm getting an error for the code above, an error saying that "Error: Argument 'MyMainController' is not a function, got undefined"

But if I will use the next code instead, the app will work

function MyMainController($scope) {
    $scope.understand = 'I now understand how the scope works3';
}

1 Answer 1

3

That is because your html tag needs to be like:

<html ng-app="MyTutorialApp">
Sign up to request clarification or add additional context in comments.

2 Comments

Wow, how did I miss that ? I'm probably very very tired :), thx for your answer
Yeah! :) Also you can remove the same from the body tag.

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.