Angularjs 加载模板网址失败
Angularjs failed to load templateurl
这是指令
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'
};
}]);
这里是项目目录
应用程序加载时出现以下错误。
[$compile:tpload] Failed to load template:
/Areas/Claim/Singlepage/directives/barnotification/test.cshtml (HTTP
status: 403 Forbidden)
我错过了什么?
您的模板未加载,因为您的 url 是绝对的,请查看 url 地址如何开始 /Areas/Claim/Singlepage...
,因此每当浏览器尝试创建 AJAX调用 url 它将搜索确切的 url,您必须相对于 baseUrl
进行调用
尝试删除第一个斜杠 Areas/Claim/Singlepage...
我怀疑这是 web.config 问题。这是 web.config <add key="webpages:Enabled" value="false" />
行,因为我要加载的页面是 .cshtml IIS chocks。从 web.config 中删除此行或将值设置为 true 可解决问题。
这是指令
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'
};
}]);
这里是项目目录
应用程序加载时出现以下错误。
[$compile:tpload] Failed to load template: /Areas/Claim/Singlepage/directives/barnotification/test.cshtml (HTTP status: 403 Forbidden)
我错过了什么?
您的模板未加载,因为您的 url 是绝对的,请查看 url 地址如何开始 /Areas/Claim/Singlepage...
,因此每当浏览器尝试创建 AJAX调用 url 它将搜索确切的 url,您必须相对于 baseUrl
尝试删除第一个斜杠 Areas/Claim/Singlepage...
我怀疑这是 web.config 问题。这是 web.config <add key="webpages:Enabled" value="false" />
行,因为我要加载的页面是 .cshtml IIS chocks。从 web.config 中删除此行或将值设置为 true 可解决问题。