问题描述
<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='https://www.6hehe.com/wenda/js/angular.js'></script><script src='https://www.6hehe.com/wenda/js/HelloAngular_MVC.js'></script></html>
function HelloAngular($scope){
$scope.greetingCon = { text: ’Hello’};
}
问题解答
回答1:var app = angular.module('myApp', []);app.controller('HelloAngular', [’$scope’, function($scope) { $scope.greetingCon = { text: ’Hello’ };}])
你试试这么能不能拿到值
回答2:因为你目前的写法是 1.3.0 之前可以运行的。如果你的 Angular 版本是 1.3.0-beta.15 之后,那这样写就不行。
这里是官方的 changelog,已经选到了那一条说明:https://github.com/angular/an...
因此,你需要把 controller 挂载到一个 module 下
里面也提到,你可以在 config 加上 $controllerProvider.allowGlobals(); 来允许 global function,但不推荐