- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我不能在模板中使用 ng-transclude
指令。我收到以下错误:
Error: [ngTransclude:orphan] Illegal use of ngTransclude directive in the template! No parent directive that requires a transclusion found. Element:
<script type="text/ng-template" id="item.html">
<div ng-transclude>
</div>
</script>
<div ng-include="'item.html'"></div>
最佳答案
ng-include
使用 element transclusion
而不是 content transclusion
,所以这是行不通的。
describe('element transclusion', function() {
it('should support basic element transclusion', function() {
module(function() {
directive('trans', function(log) {
return {
transclude: 'element',
priority: 2,
controller: function($transclude) { this.$transclude = $transclude; },
compile: function(element, attrs, template) {
log('compile: ' + angular.mock.dump(element));
return function(scope, element, attrs, ctrl) {
log('link');
var cursor = element;
template(scope.$new(), function(clone) {cursor.after(cursor = clone);});
ctrl.$transclude(function(clone) {cursor.after(clone);});
};
}
};
});
});
inject(function(log, $rootScope, $compile) {
element = $compile('<div><div high-log trans="text" log>{{$parent.$id}}-{{$id}};</div></div>')($rootScope);
$rootScope.$apply();
expect(log).toEqual('compile: <!-- trans: text -->; link; LOG; LOG; HIGH');
expect(element.text()).toEqual('1-2;1-3;');
});
});
When we specify the transclude: 'element' option we cannot use a template, so we cannot even specify where to put the transcluded element with the ng-transclude attribute.
使用装饰器
来代替content transclusion
:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="transcludeExample">
<script type="text/ng-template" id="foo">
</script>
<script>
function delegator($delegate)
{
/* Override transclude configuration */
$delegate[0].transclude = true;
return $delegate;
}
function provider($provide)
{
/* Deocrate ng-include with a proxy function */
$provide.decorator('ngIncludeDirective', ["$delegate", delegator]);
}
/* Inject the provider and the delegator methods with services */
provider['$inject'] = ['$provide'];
delegator['$inject'] = ['$delegate'];
/* Inject the module with the new provider */
angular.module('transcludeExample', []);
angular.module("transcludeExample").config(["$provide",provider]);
</script>
<div>Non-transcluded ID: {{$id}}</div><div ng-include src="'foo'" data-foo="{{$id}}">Transcluded ID: {{$id}}<ng-transclude></div></div>
</body>
内容嵌入定义如下:
allowing a directive to wrap arbitrary child content inside additional template HTML.
而元素嵌入意味着:
the template we pass in to the directive will replace the element with
ng-transclude
directive.
引用资料
关于angularjs - 在 ngInclude 中使用 ngTransclude,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32202170/
我有一些部分模板,其中位置通过 ng-click 根据用户操作进行更改: Add Test Script 这很好用,除非我上面的按钮在部分本身内部,所以如果 testScriptForm.html
我正在开发一个网络应用程序,我必须通过基于位置 url 从磁盘加载自定义主题(这意味着一堆 html 文件,每个文件都有许多 js/css 文件作为依赖项)来进行个性化设置.由于我的元素已经使用了 A
我的模板包含 JS,因为它们被称为 JS 未执行,请您有想法。 例如,在我的 JS 文件 script.js 中,我有一些方法适用于我的模板中的 HTML 元素,但它不起作用,请给个主意。 例子 :
我正在使用 ngInclude指令加载 HTML 片段。现在我正在寻找传递动态 URL 的最佳方式。我知道我可以使用字符串连接创建 URL: 在我眼里这有点难看。 ngHref和 ngSrc例如,接
我有一个指令,它的工作需要一个独立的范围它接收的参数之一是传递给 ng-include 的 templateUrl 有没有办法告诉 ng-include 将其范围生成为调用我的指令的父范围的子范围?
我正在使用 nginclude 来更改局部 View ,在局部 View 中,我有一个 Controller ,在该 Controller 中,我想从更改 a 变量的父作用域调用一个函数。我该怎么做?
当我把它放在我的 HTML 中时,它工作正常: 但是当我尝试使用 jQuery 动态创建 ngInclude 指令时(在 DOM 准备好之后),它不起作用: $(function() { var
我正在制作一个巴士预订系统。为此,我想使用 angularjs 的 ng-include 指令添加登录页面(这是一个单独的 html 文件),但每次我添加它时,它都会编译并得到评论。此外,我尝试了一些
ngSwitch 和 ngInclude 有什么区别? 我真的需要了解其中的区别,这样我才能继续我的项目。 ngSwitch 是否仅隐藏 dom 元素? 最佳答案 您可能会发现 v1.1.4 文档更有
这是一个骗子:http://plnkr.co/edit/F6QM4KUU8DPNq6muInGS?p=preview 使用 ng-include 包含 html 文件,并在同一标记中设置 ng-con
我不能在模板中使用 ng-transclude 指令。我收到以下错误: Error: [ngTransclude:orphan] Illegal use of ngTransclude directi
我正在尝试构建一个模块化的 ngInclude。我的意思是 ngIncluded JSP 将引入它需要的所有依赖项并在呈现之前重新编译自身。 同一个文件在一个页面上多次使用。主页有几个选项卡 - 所有
我有这个小脚本,angular 中的 Controller 完全是空的,所以什么也没有。 我的问题是为什么我不能运行到 ngIncludes(顺便说一下没有错误)? 最
只是想了解在 AngularJS 中使用 ngView 和 ngInclude 的方法的确切区别。什么时候使用一个而不是另一个是正确的?谢谢。 最佳答案 ngView 与路由一起工作,并且对于 Ang
我打算在具有不同 Controller 的多个 View 中使用一个模板。 但现在我意识到我不能只在模板中编写通用绑定(bind),因为值将放在 $scope.concreteControllerNa
我试图在第一页 View 中获取所有部分,以便在应用程序查看期间不会下载 html。 一种方法是在 index.html 中添加模板。 . This is the content of the
我开始学习 AngularJs 但面临一个问题。 ng Include 指令在 jQuery 弹出窗口中不起作用。这是代码示例:( http://jsfiddle.net/kgupkx87/13/ )
当我从纯 HTML 演示构建 Angular 应用程序时,我正在努力思考如何让 ng-include 不使用额外的 DOM 元素。我正在使用相当纤薄的 HTML 和完全开发的、紧密 DOM 耦合的 C
我遇到了 ngRepeat 指令的一些意外行为。这是一个非常简单的示例: test with directive
我正在尝试创建一个指令来加载自定义模板,但如果自定义模板不存在,则加载默认模板。 这是我的代码: HTML: 指令: angular.module('app') .directive("my
我是一名优秀的程序员,十分优秀!