使用angularJS和asp.net MVC解析相对模板URL

使用angularJS和asp.net MVC解析相对模板URL,angularjs,angularjs-directive,asp.net-mvc-5,Angularjs,Angularjs Directive,Asp.net Mvc 5,我已经搜索了很多帖子,但仍然无法使run成为一个非常基本的自定义指令,因为templateUrl没有正确解析 我有一个AngularJSController和一个索引操作(asp.NETMVC),调用View/AngularJS/Index.cshtml,非常基本。在这里,我称之为自定义指令: <product-title></product-title> 如您所见,它应该使用操作方法ProductTitle调用控制器angularjstemplatescocontro

我已经搜索了很多帖子,但仍然无法使run成为一个非常基本的自定义指令,因为
templateUrl
没有正确解析

我有一个
AngularJSController
和一个索引操作(asp.NETMVC),调用View/AngularJS/Index.cshtml,非常基本。在这里,我称之为自定义指令:

<product-title></product-title>
如您所见,它应该使用操作方法
ProductTitle
调用控制器
angularjstemplatescocontroller
(asp.net MVC)。这将返回我对angularJS的部分问题是:AngularJS调用
{root path}/AngularJS/AngularJSTemplates/ProductTitle
,而不是
{root path}/AngularJSTemplates/ProductTitle


我错过了什么?我真的需要将根路径定义为javascript全局路径并将其用于绝对路径吗?

只需将指令替换为以下指令:

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。我认为它会起作用。

您可能需要定义基本url,请参阅有关使用相对链接的文档

app.directive('productTitle', function () {
        return {
            restrict: 'E',
            // ends up with wrong url '{root-path}/AngularJS/AngularJSTemplates/ProductTitle'
            templateUrl: 'AngularJS/AngularJSTemplates/ProductTitle'
        }
    });