2016-05-15 93 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,这个问题没有提到。 –