我一直在尝试在 Razor 视图 MVC 5 中调用 angularjs 自定义指令模板 URL,但无法获取文件。在我的项目中,我使用的是没有$routeProvider或angularjs路由的angularjs,因为我的应用程序直接依赖于mvc路由。有人可以帮我解决这个问题吗?
These are my templates....
~/Areas/Sales/Views/Orders/Edit.cshtml ~/Areas/Sales/Views/Orders/Add.cshtml ~/Areas/Sales/Views/Orders/Update.cshtml ~/Areas/Sales/Views/Orders/Delete.cshtml
This is my directive.
app.directive("test", function(){
return{
restrict:'AE',
scope: {
emp: '='
},
templateUrl: '~/Areas/Sales/Views/Orders/Edit.cshtml'
}
});
app.config(['$routeProvider',
function ($routeProvider) {
$routeProvider.
when('/index', {
templateUrl: '/home/index',
controller: 'QuizController' //new
}).
when('/quiz', {
templateUrl: '/home/quiz',
controller: 'QuizController' //new
}).
otherwise({
redirectTo: '/index'
});
}]);
<div ng-view></div>
var elem;
app.directive('parentDirective', function ($http, $compile) {
return {
restrict: 'E',
compile: function (element, attrs) {
var controllerurl = attrs.controllerurl;
elem = element;
if (controllerurl) {
return function(scope,element){
$http.get(controllerurl + '/GetWizardItems').
success(function (data, status, headers, config) {
var x = angular.element('<child-directive></child-directive><child-directive></child-directive>');
element.append(x);
$compile(x)(scope);
});
}
}
}
}
});