angularjs - 为什么 ng-include 使用 2 组引号?

标签 angularjs angularjs-ng-include

ng-include 期望 Angular 表达式评估为 URL,因此当我们编写 ng-include="page.html"时,这意味着 $scope 的页面对象的 html 属性。当我们写 ng-include="'page.html' "(page.html 周围的单引号,用双引号括起来)时,它就是 Angular 表达式:计算值为 page.html 的字符串

最佳答案

angular 指令中的所有名称都描述了 angular 的默认行为。想想你放在双引号内的东西是简单的 Angular 变量名。像 ng-include="page.html" 一样,Angular 使用它来访问名为 page 的对象的名为 html 的属性在 scope 变量中。在您的情况下,当您想传递原始字符串而不是变量名时,您可以添加更多引号(单引号)以让 Angular 知道您传递的参数是字符串,而不是范围的任何变量。像 ng-include="'page.html'".

希望能解开你的困惑。

关于angularjs - 为什么 ng-include 使用 2 组引号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38939700/

相关文章:

jquery - 仅为嵌套模态显示模态背景

javascript - 不使用 Javascript 库的 AngularJS 部分 View

javascript - 在angularjs ng-include中延迟包含html文件

javascript - ng-include 用于页眉/页脚

angularjs - ng-include 使用哪种 http 方法来加载提供给它的 url?

angularjs - Angular (1.5.8) 动态组件

AngularJS ng-include : onload calling a function defined in included controller

javascript - AngularJS Protractor : randomly fail in headless mode (Firefox)

javascript - Angular -Js : not able to access array elements in different function call within same controller

javascript - 特定API或localStorage