angular.js - AngularJS's Controller (HelloAngular) does not take effect and cannot get the value
世界只因有你
世界只因有你 2017-06-10 09:48:09
0
2
724

<html ng-app>
<head>Angular Model</head>
<body>

<p>
    <input ng-model="greeting.text"/>
    <p>{{greeting.text}}, AngularJS</p>
</p>
<p ng-controller="HelloAngular">
    <p>{{greetingCon.text}}, AngularJS</p>
</p>

</body>
<script src="js/angular.js"></script>
<script src="js/HelloAngular_MVC.js"></script>
</html>

function HelloAngular($scope){

$scope.greetingCon = {
    text: 'Hello'
};

}

世界只因有你
世界只因有你

reply all(2)
过去多啦不再A梦
var app = angular.module("myApp", []);
app.controller("HelloAngular", ['$scope', function($scope) {
  $scope.greetingCon = {
    text: 'Hello'
  };
}])

Try to see if you can get the value

小葫芦

Because your current writing method can run before 1.3.0. If your Angular version is after 1.3.0-beta.15, writing this way will not work.

Here is the official changelog, the description has been selected: https://github.com/angular/an...

Therefore, you need to mount controller under a module

It is also mentioned that you can add $controllerProvider.allowGlobals(); to config to allow global function, but it is not recommended

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template