Angularjs无法加载templateurl

时间:2017-09-11 23:17:51

标签: angularjs angularjs-directive

这是指令

moduleDirectives
.directive('barNotification', ['$compile', '$timeout', function ($compile, $timeout) {
    return {
        restrict: 'E',
        replace: true,
        scope: {
            barShow:'=',
            barType: '=',
            barMessage:'=',
            barAllowClose:'=',
            onClose: '&',
            onOpenSlopeSetting: '&'
        },
        link: function (scope, element, attr) {
            scope.contentElement = element;
            scope.onCloseExists = 'onCloser' in attr;
            scope.$watch('barMessage', function () {
                $timeout(
                        function () {
                            angular.element(scope.contentElement[0].querySelector('#barMessage')).replaceWith($compile('<div id="barMessage">' + scope.barMessage + '</div>')(scope));
                        });
            }, true);
        },
        templateUrl: '/Areas/Claim/Singlepage/directives/barnotification/barNotification.cshtml',
        controller: 'barNotificationController'
    };
}]);

这是项目目录

enter image description here

当应用加载时,我收到以下错误。

  

[$ compile:tpload]无法加载模板:   /Areas/Claim/Singlepage/directives/barnotification/test.cshtml(HTTP   状态:403禁止)

我错过了什么?

2 个答案:

答案 0 :(得分:0)

您的模板未加载,因为您的网址是绝对的,请查看网址如何启动/Areas/Claim/Singlepage...,因此每当浏览器尝试对该网址进行AJAX调用时,它都会搜索该网址,您有拨打相对于baseUrl

的电话

尝试删除第一个斜杠Areas/Claim/Singlepage...

答案 1 :(得分:0)

我怀疑是web.config问题。这是web.config <add key="webpages:Enabled" value="false" />的一行,因为我尝试加载的页面是.cshtml IIS阻塞它。从web.config中删除此行或将值转为true可解决问题。