gpt4 book ai didi

javascript - ng 路线不工作指令

转载 作者:行者123 更新时间:2023-12-03 11:03:46 24 4
gpt4 key购买 nike

我可以在 Angular Directive(指令)中执行 ng-view 吗?我尝试过,但显示此错误。

错误:[$injector:unpr] http://errors.angularjs.org/1.2.13/ $injector/unpr?p0=%24templateRequestProvider%20%3C-%20%24templateRequest%20%3C-%20%24route%20%3C-%20ngViewDirective

我的代码:

index.html

<body ng-app="Learning">
<div ng-controller="learning">
<div ng-switch-when="1" >
<div introduction-page></div>
</div>
</div>
</body>

app.js

var Learn = angular.module("Learning",['ngRoute']);

Learn.directive("introductionPage", function() {
return {
restrict:'EA',
transclude:false,
templateUrl:'views/intro.html',
replace:true,
controller: introController
}

function introController($scope,$http,$location) {
$scope.onClick = function() {
$location.path('course');
}
}
});

Learn.config(function($routeProvider) {
$routeProvider
.when('/course', {
templateUrl : 'views/course-ch1.html',
controller : 'courseController'
})

.otherwise({redirectTo: '/'});
});

function courseController($scope) {
alert("in course");
}

简介.html

<div style="width:100%;height:662px">

INTRODUCTION........

<div ng-view></div>
<input type="button" style="width:100px;height:40px;" label="enter" ng-click="onClick()">

</div>

这样可以吗?

谢谢

最佳答案

您可以在指令中使用 ng-view 但需要使用 transinclude : true,property:-

喜欢

<div introduction-page>
<ng-view></ng-view>
</div>

如示例所示:- http://plnkr.co/edit/0813dA?p=preview

关于javascript - ng 路线不工作指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27958385/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com