AngularJs模板网址

时间:2016-05-15 20:26:25

标签: angularjs

如果我应该使用

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.';
    });

2 个答案:

答案 0 :(得分:2)

尝试使用部分的绝对路径

例如,如果您的应用程序位于App Directory中而不是使用:

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

答案 1 :(得分:0)

在_Layout.cshtml中的某处声明

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

然后在templateUrl中将其用作

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