Tania
Tania

Reputation: 3

Controller value is not populated properly

Anything I am writing in my controller is not reflected in the HTML. I removed everything else in my code and just tried to render a simple message, but that, too, is not working.

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <script src="Scripts/angular.js"></script>
    <link href="Style/style.css" rel="stylesheet" />
    <script src="app/main.js"></script>
</head>
<body ng-app="mainApp">
    <div>
        <div ng-controller="MainCnt">
            <h1>
                {{message}}
            </h1>
        </div>        
    </div>
</body>
</html>

And this is the JS part:

(function() {
    var main = angular.module("mainApp",[]);
    var MainController = function($scope) {
        $scope.message = "Hello!";
    };
    main.controller = ("MainCnt",MainController);
}());   

What am I doing wrong? Since the last hour I have not been able to show a simple message in my HTML. Instead it just shows {{ message}}.

Upvotes: 0

Views: 28

Answers (1)

Sven Schoenung
Sven Schoenung

Reputation: 30574

You're making an assignment in this line:

main.controller = ("MainCnt",MainController);

What you actually want to do is call the controller() method:

main.controller("MainCnt",MainController);

Upvotes: 1

Related Questions