Alon
Alon

Reputation: 3906

angular app.controller raises an error

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

Upvotes: 1

Views: 78

Answers (1)

AlwaysALearner
AlwaysALearner

Reputation: 43947

That is because your html tag needs to be like:

<html ng-app="MyTutorialApp">

Upvotes: 3

Related Questions