我正在练习使用模块和嵌入式 HTML 编写 AngularJS 应用程序。有谁知道为什么ng-include
的来源下面的指令要求双引号内包含单引号,而 <script>
的源代码文件只需要一种类型的引号?
我知道一个事实:ng-include
如果我只使用一种类型的引号,则指令不起作用。但不知道为什么会这样。
谢谢!
<DOCTYPE html>
<html>
<head>
<title>
Angularjs practice
</title>
</head>
<body>
<div ng-app="main" ng-controller="stController">
<div ng-include="'angularjs/src/include/main.htm'">
</div>
<div ng-include="'angularjs/src/include/subjects.htm'">
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js"></script>
<script src="angularjs/src/module/mainApp.js"></script>
<script src="angularjs/src/module/studentController.js"></script>
</body>
</html>
最佳答案
ng-include
需要一个计算 URL 的 Angular 表达式
例如,如果您编写 ng-include="test.html"
,则表示 $scope 的测试对象的 html 属性。
当你说ng-include="'test.html'"
时,这是一个 Angular 表达式。在本例中,字符串的计算结果为 test.html
这是官方文档
关于javascript - 使用 angularjs 指令的引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35467685/