我想在我的angularjs指令的html模板中包含扩展pageUrl。这是我的情况最简单的例子。如何在指令的html模板中包含pageURL
angular.module('pageInclude', [])
.directive('pageInclude', function() {
return {
restrict: 'E',
replace: true,
scope: {
extUrl: '='
},
template: "<div><h1>Page Include</h1><ng-include src=\"'{{extUrl}}'\"></ng-include></div>"
}
});
我的HTML代码是:
<page-include ext-url="example/extendForm.html"></page-include>
然后我得到了以下错误:
Error: [$interpolate:noconcat] Error while interpolating: '{{extUrl}}' Strict Contextual Escaping disallows interpolations that concatenate multiple expressions when a trusted value is required. See http://docs.angularjs.org/api/ng .$sce http://errors.angularjs.org/1.3.15/ $interpolate/noconcat?p0='%7B%7BextUrl%7D%7D' at REGEX_STRING_REGEXP (angular.js:63) at $interpolate (angular.js:10152) at addAttrInterpolateDirective (angular.js:8101) at collectDirectives (angular.js:7203) at compileNodes (angular.js:7035)
有没有什么办法可以使这种情况下工作?谢谢你的回复。
感谢。我试过这种方式,但它仍然无法正常工作。主要原因是无法在指令模板中工作 –
Coral
我在小提琴中添加示例 –
感谢Tek的例子,它的工作原理我的错误是将'inside ng-include的src属性。 – Coral