Answer the question
In order to leave comments, you need to log in
Why does the code in curly braces stop initializing when adding ng-controller to div?
Here is the code: as soon as I add ng-controller to the div, the code in {{}} such brackets does not work. name is not initialized, and for the 1+7 check, it is printed like that. Tell me what's the problem?
<!doctype html>
<html lang="en" ng-app>
<head>
<meta charset="utf-8">
<title>My HTML File</title>
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css">
<link rel="stylesheet" href="css/app.css">
<script src="bower_components/angular/angular.js"></script>
<script>
var DemoCtrl = function($scope){
$scope.name = 'world';
}
</script>
</head>
<body>
<div ng-controller='DemoCtrl'>
<p>Hello {{name}}</p>
<p>1 + 7 = {{1+7}}</p>
</div>
</body>
</html>
Answer the question
In order to leave comments, you need to log in
You need to describe the controller as mentioned earlier.
var myApp = angular.module('myApp', []);
myApp.controller('MyCtrl', function ($scope) {
...
});
ng-app="myApp"
Is this a normal declaration of the controller itself? Otherwise, it's necessary. And where is your ng-app directive?
There is no controller declaration code. Should be something like:
var myApp = angular.module('myApp', []);
myApp.controller('MyCtrl', function ($scope) {
...
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question