问题描述
限时送ChatGPT账号..我想知道为什么在 ng-app
中使用空字符串会出现问题.在 w3school 提供的 example 中,我尝试使用空字符串来命名ng-app 如下,但失败了.
<script src="http://ajax.googleapis/ajax/libs/angularjs/1.3.14/angular.min.js"><身体><p>尝试更改名称.</p><div ng-app="" ng-controller="myCtrl">名字:<input type="text" ng-model="firstName"><br>姓氏:<input type="text" ng-model="lastName"><br><br>全名:{{firstName + " " + lastName}}<脚本>var app = angular.module('', []);app.controller('myCtrl', function($scope) {$scope.firstName="约翰";$scope.lastName="母鹿";});</html>
即使制作 " "
也会使 ng-app 指令起作用.有什么想法吗?
我想知道这个问题的原因是我学习了一个示例,无需初始化控制器即可实现相同的功能,并且 ng-app 是一个空字符串.
<script src="http://ajax.googleapis/ajax/libs/angularjs/1.3.14/angular.min.js"><身体><div ng-app="" ng-init="firstName='John'"><p>名字是<span ng-bind="firstName"></span></p></html>
解决方案 你必须为你的模块设置一个名称,否则不使用模块并从你的 html 中删除ng-app".
I wonder why it seems a problem using empty strings for ng-app
.
In the example provided by w3school, I attempted using empty string to name the ng-app as below, but failed.
<!DOCTYPE html>
<html>
<script src= "http://ajax.googleapis/ajax/libs/angularjs/1.3.14/angular.min.js">
</script>
<body>
<p>Try to change the names.</p>
<div ng-app="" ng-controller="myCtrl">
First Name: <input type="text" ng-model="firstName"><br>
Last Name: <input type="text" ng-model="lastName"><br>
<br>
Full Name: {{firstName + " " + lastName}}
</div>
<script>
var app = angular.module('', []);
app.controller('myCtrl', function($scope) {
$scope.firstName= "John";
$scope.lastName= "Doe";
});
</script>
</body>
</html>
Even making a " "
will make the ng-app directive work. Any ideas?
The reason I was wondering this question is that I learned one example realizing same functionalities without initializing a controller and the ng-app is an empty string.
<!DOCTYPE html>
<html>
<script src= "http://ajax.googleapis/ajax/libs/angularjs/1.3.14/angular.min.js">
</script>
<body>
<div ng-app="" ng-init="firstName='John'">
<p>The name is <span ng-bind="firstName"></span></p>
</div>
</body>
</html>
解决方案
you have to set a name to your module, or otherwise not use a module and delete the 'ng-app' from you html.
这篇关于使用空字符串(“")作为 ng-app 的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论