【发布时间】:2016-03-19 05:13:23
【问题描述】:
以下是我用打字稿类编写的角度指令代码。 当我在浏览器中运行指令时。我得到错误
加载模板失败:../Templates/inputcontrol.html(HTTP 状态:404 未找到)- 错误:$compile:tpload 加载模板时出错
我正在使用 asp.net mvc
如何在angular中设置path或templateUrl?
<input-control a="shan"></input-control>
虽然相对路径没问题。
class InputControl implements ng.IDirective {
restrict = "E";
scope = {
a: "=a"
};
templateUrl = "../Templates/inputcontrol.html";
controller = ["$scope", ($scope: any) => {
console.log("this this controller", $scope.a);
}];
controllerAs = "inputcontroller";
constructor(private $location: ng.ILocationService) {
}
link = (scope: ng.IScope, element: ng.IAugmentedJQuery, attrs: ng.IAttributes, ctrl: any) => {
console.log(this.$location);
};
static factory(): ng.IDirectiveFactory {
const directive = ($location: ng.ILocationService) => new InputControl($location);
directive.$inject = ["$location"];
return directive;
}
}
angular.module("SheetApp").directive("inputControl", InputControl.factory());
【问题讨论】:
标签: javascript angularjs asp.net-mvc angularjs-directive typescript