2016-05-15 97 views
1

如果我要使用AngularJs模板URL

templateUrl: 'Content/Custom/Login.html' 

只有當用戶在Home/Index控制器會工作。如果用戶將在另一個控制器,如Home/About,它不應該。

http://localhost:7602/Home/Content/Custom/Login.html無法加載 資源:

因爲模板位於

http://localhost:7602/Content/Custom/Login.html 

如何解決這一問題?什麼是模板聲明的正確方法?

$mdDialog.show({ 
     controller: DialogController, 
     templateUrl: 'Content/Custom/Login.html', 
     parent: angular.element(document.body), 
     targetEvent: ev, 
     clickOutsideToClose: true, 
     fullscreen: useFullScreen 
    }) 
    .then(function (answer) { 
     $scope.status = 'You said the information was "' + answer + '".'; 
    }, function() { 
     $scope.status = 'You cancelled the dialog.'; 
    }); 
+0

您是否定義了? –

回答

2

嘗試使用絕對路徑到您的諧音

舉例來說,如果您的應用程序在應用程序目錄比使用:

templateUrl: '/App/Content/Custom/Login.html 
+0

這工作正常,直到你有一個URL,如http:// localhost/myapp。 –

0

某處聲明在_Layout.cshtml

<script> 
     window.contentUrl = @Html.Raw(HttpUtility.JavaScriptStringEncode(Url.Content("~/Content/"), true)); 
</script> 

然後在你的templateUrl中使用它作爲

templateUrl: contentUrl + "/Custom/Login.html' 
+0

這是一個很好的解決方案,但依賴於ASP.NET Razor,這個問題沒有提到。 –