我已经搜索了许多帖子,但仍然无法运行一个非常基本的自定义指令,因为templateUrl没有得到正确的解析。
我有一个带有索引操作( AngularJSController MVC)的asp.net,它调用了View/AngularJS/Index.cshtml,非常基本。在那里,我调用一个自定义指令:
<product-title></product-title>概述如下:
app.directive('productTitle', function () {
return {
restrict: 'E',
// ends up with wrong url '{root-path}/AngularJS/AngularJSTemplates/ProductTitle'
templateUrl: 'AngularJSTemplates/ProductTitle'
}
});如您所见,它应该使用动作方法AngularJSTemplatesController (asp.net MVC)调用控制器ProductTitle。这将返回angularJS的部分。,问题是: AngularJS调用{root-path}/AngularJS/AngularJSTemplates/ProductTitle而不是{root-path}/AngularJSTemplates/ProductTitle.
我在这里错过了什么?我真的需要在某个地方将根路径定义为javascript-全局,并将其用于绝对路径吗?
发布于 2014-08-31 12:33:55
您可能需要定义基url,请参阅有关使用相对链接这里的文档。
发布于 2014-08-31 12:33:43
将指令替换为折叠指令:
app.directive('productTitle', function () {
return {
restrict: 'E',
// ends up with wrong url '{root-path}/AngularJS/AngularJSTemplates/ProductTitle'
templateUrl: 'AngularJS/AngularJSTemplates/ProductTitle'
}
});我认为指令找不到你的模板。AngularJS/AngularJSTemplates/ProductTitle是模板的相对url。我觉得会管用的。
https://stackoverflow.com/questions/25591832
复制相似问题