AMAN AGARWAL
AMAN AGARWAL

Reputation: 23

AngularJS - why controller is not working?

I have this simple code in my app.js file:

(function(){
    var app = angular.module('searchHotels', []);

    app.controller = ("PlaceController", function(){
        this.place = shop;
    });

    var shop = {
        name: 'supermarket',
        distance: 100
    };
})();

Here is the index.html file's code:

<!doctype.html>
<html ng-app="searchHotels">

<head>
    <script type="text/javascript" src="angular.min.js"></script>
    <script type="text/javascript" src="app.js"></script>
</head>

<body>

    <div ng-controller="PlaceController as placeC">
        <h3> {{placeC.place.name}} </h3>
    </div>

</body>

</html>

In the output, my {{placC.place.name}} expression is not replaced by the data it was meant to show. It just outputs "{{placeC.place.name}}" itself. What am I missing here? Thanks!

Upvotes: 0

Views: 48

Answers (1)

dfsq
dfsq

Reputation: 193261

Angular controller definition is a method call, not assignment. Correct code:

app.controller("PlaceController", function(){
    this.place = shop;
});

Upvotes: 5

Related Questions