2014-08-31 41 views
0

我已经搜索了很多帖子,但仍然无法运行非常基本的自定义指令,因为templateUrl未正确解析。使用angularJS和asp.net解析相对模板网址MVC

我有一个AngularJSController与索引行动(asp.net MVC),调用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全局,并将其用于绝对路径吗?

回答

0

您可能需要定义基础URL,请参阅使用相对链接here

-2

只是follwing指令替换指令:

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

我想指令不能找到您的模板。 AngularJS/AngularJSTemplates/ProductTitle是您的模板的相对路径。我认为它会起作用。

+0

都能跟得上那现在肯定是错误的文件... – sl3dg3 2014-08-31 18:10:49