2014-08-31 44 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