使用空字符串("")作为名称NG-应用 [英] Using empty string ("") as name for ng-app
问题描述
我不知道为什么它使用空字符串似乎是一个问题为 NG-应用
。
在例如通过w3school提供的,我试图用空字符串来命名NG-应用程序如下,但是失败了。
<!DOCTYPE HTML>
< HTML和GT;
&所述; SCRIPT SRC =http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js\">
< / SCRIPT>
<身体GT;< P>尝试改变名称和LT; / P>< DIV NG-应用=NG控制器=myCtrl> 名字:<输入类型=文本NG模型=名字>< BR>
姓:LT;输入类型=文本NG模型=姓氏>< BR>
< BR>
全名:{{的firstName ++ lastName的}}< / DIV><脚本>
VAR应用= angular.module('',[]);
app.controller('myCtrl',函数($范围){
$ scope.firstName =约翰;
$ scope.lastName =李四;
});
< / SCRIPT>< /身体GT;
< / HTML>
即使制作,
将使得NG-应用指令工作。任何想法?
我想知道这个问题的原因是,我学会了一个例子实现相同的功能,而不初始化控制器和NG-应用程序是一个空字符串。
<!DOCTYPE HTML>
< HTML和GT;
&所述; SCRIPT SRC =http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js\">
< / SCRIPT>
<身体GT;< DIV NG-应用=NG-的init =名字='约翰'>&所述; P>将名称为<跨度纳克绑定=名字>&下; /跨度>&下; / P>< / DIV>< /身体GT;
< / HTML>
你有一个名称设置为你的模块,或不使用一个模块,并从您删除'NG-应用的HTML。
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.com/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.com/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.
这篇关于使用空字符串(&QUOT;&QUOT;)作为名称NG-应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!