I am new in Angular.js
and start learning angular on plunker.co
. The problem is when I use ng-controller
in any tag of html
page , angular
stops working. I mean {{ 4+4 }}
display as it is just after the using of ng-controller
.
this is code from Plunker.co
<html ng-app>
<head>
<script data-require="[email protected]" data-semver="1.3.15"
src="https://code.angularjs.org/1.3.15/angular.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body ng-controller="MainController">
<h1>Hello Plunker!</h1>
{{8*8}}
{{message}}
</body>
</html>
without ng-controller
it displays 64
as output but with ng-controller
is displays as it is like {{8*8}}
. why it is happening. Please give some advice. thnks in advance. :)
script.js
var MainController = function($scope){
$scope.message = "Hello World!";
}
edited
Now message
attirbute value is not displaying on page.
First try to set a name for your app :
<html ng-app="myApp">
then set a name for your controller :
<body ng-controller="MainController">
and finally, all you need to do is to define your app :
myApp = angular.module('myApp', []);
and try this definition for your controller :
myApp.controller('MainController', function($scope) {
$scope.message = "Hello World!";
});
ng-controller
expects a parameter that is the name of the controller defined in your angular code. Something like ng-controller=foo
. You should read up more on how Controllers work
I'm not sure if you can use in the AngularJS controllers without name. Please set a name for your controller and it should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With