I have am new to Angular and messing around with Controllers. I created this simple controller function:
(function(){
var app = angular.module('store', []);
app.controller('StoreController', function(){
this.product = gem;
});
var gem = {
name: "Dodecahedron",
price: 2.95,
description: '...'
};
})();
When I call this controller under my index.html, it works perfectly. Here is my index.html:
<html>
<head>
<script src = "angular.min.js"></script> <!--ANGULAR SOURCE-->
<script src = "app.js"></script> <!--APP SOURCE-->
<link rel = "stylesheet" href = "bootstrap.css" type = "text/css"> <!--BOOTSTRAP-->
</head>
<body ng-app = "store">
<div ng-controller="StoreController as store">
<h1>{{store.product.name}}</h1>
<h2> {{store.product.price}} </h2>
<p> {{store.product.description}} </p>
</div>
</body>
</html>
My code is working find and as expected. However, I don't get what the purpose of the last set of parentheses is in my controller function because once I take it out, my controller no longer works. It seems unnecessary, but for some reason my controller won't work without it. Could someone provide me with why this isn't working?
thanks!