Andrey Langovoy
Andrey Langovoy

Reputation: 795

Angular does not display data in an output html file

I have app.js file that contains the following code:

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

app.controller('StoreController', function () {
    this.product = gem;
});

var gem = {
    name: 'Dodechaedron',
    price: 2.95,
    description: '...',
};

})();

I also have the following html file that contains the following code:

<div ng-app="StoreController as store">
    <h1>{{store.product.name}}</h1>
    <h2>{{store.product.price}}</h2>
    <p>{{store.product.description}}</p>
</div>
<script src="Scripts/angular.min.js"></script>
<script src="app.js"></script>

it also includes

<html xmlns="http://www.w3.org/1999/xhtml" ng-app="store">

When I build the app - nothing happens. The question is - where is mi data from the app.js file?

Thank you.

Upvotes: 0

Views: 515

Answers (2)

CYB
CYB

Reputation: 1106

Your app name should be store.

<html ng-app='store'>

StoreController is a controller so it should be used in ng-controller

Upvotes: 1

rob
rob

Reputation: 18523

You're using ng-app instead of ng-controller. If your change your html to this it should work:

<div ng-controller="StoreController as store">

Upvotes: 1

Related Questions