AngularJS NG-包括不包括视图,除非传递$范围 [英] AngularJS ng-include does not include view unless passed in $scope

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

问题描述

这是错误的假设 ngInclude 可采取原始的路径?我一直试图把我的 ngInclude 如下:

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;
});

在我的index.html

In my index.html

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

确实 ngInclude 只除了关闭范围的值?如果是这样,为什么是这样而不是直包括HTML的部分。

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-包括 接受一个前pression。
如果您想直接在那里指定明确的URL,你必须给一个字符串。

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-包括不包括视图,除非传递$范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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