AngularJS ng-include 不包含视图,除非传入 $scope [英] AngularJS ng-include does not include view unless passed in $scope

查看:23
本文介绍了AngularJS ng-include 不包含视图,除非传入 $scope的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设 ngInclude 可以采用原始路径是错误的吗?我一直试图设置我的 ngInclude 如下:

这不起作用,但如果我做这样的事情它确实有效.

//HeaderControllerapp.controller('HeaderCtrl', function($scope){$scope.templates = {[模板:{ 网址:'views/header.html'}]};$scope.template = $scope.templates[0].template;});

在我的 index.html

<div ng-include src="template.url"></div>

ngInclude 是否仅适用于超出范围的值?如果是这样,为什么是这样,而不是直接包含 html 部分.

解决方案

ng-include 接受一个表达式.如果你想直接在那里指定显式 URL,你必须给出一个字符串.

<div ng-include src="'page.html'"></div>

Is it wrong to assume that ngInclude can take a raw path? I keep trying to set my ngInclude as follows:

<div ng-include src="views/header.html"></div>

This does not work but if I do something like this it does work.

// HeaderController
app.controller('HeaderCtrl', function($scope){
   $scope.templates = {[
     template: { url: 'views/header.html' }
   ]};

   $scope.template = $scope.templates[0].template;
});

In my index.html

<div ng-controller="HeaderCtrl">
  <div ng-include src="template.url"></div>
</div>

Does ngInclude only except values off of the scope? If so why is it this way and not a straight include of the html partial.

解决方案

ng-include accepts an expression. If you want to specify the explicit URL directly in there, you have to give a string.

<div ng-include src="'page.html'"></div>

这篇关于AngularJS ng-include 不包含视图,除非传入 $scope的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆