我写了这段代码
<html ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"> </script>
<script>
angular.module('scopeExample', [])
.controller('MyController', ['$scope', function($scope) {
$scope.username = 'World';
$scope.sayHello = function() {
$scope.greeting = 'Hello ' + $scope.username + '!';
};
}]);
</script>
</head>
<body>
<div ng-controller="MyController" >
Your name:
<input type="text" ng-model="username">
<button ng-click='sayHello()'>greet</button>
<hr>
{{greeting}}
</div>
</body>
</html>
代替从文本框中获取输入,它只是打印{{greeting}},甚至文本框也没有用world初始化。
答案 0 :(得分:1)
设置在顶部的html标记ng-app ="scopeExample"
答案 1 :(得分:0)
定义你的ng-app =“scopeExample”,Fiddle。
angular.module('scopeExample', [])
.controller('MyController', ['$scope', function($scope) {
$scope.username = 'World';
$scope.sayHello = function() {
$scope.greeting = 'Hello ' + $scope.username + '!';
};
}]);
答案 2 :(得分:0)
缺少应用标记模块名称,您可以在HTML中添加ng-app =“scopeExample”。
<html ng-app="scopeExample">
需要自举角度 参考: - https://docs.angularjs.org/api/ng/directive/ngApp
答案 3 :(得分:0)
function HelloCntl($area) {
$area.test= 'Demo';
}
<div ng-controller="MyController">
Your name: <input type="text" ng-model="test"/>
<hr/>
Hello {{test|| "Demo"}}!
</div>