我可以在角度指令中进行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");
}
intro.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>
有可能这样做吗?
由于
答案 0 :(得分:1)
您可以在指令中使用ng-view,但在transclude:true,property: -
的帮助下像
<div introduction-page>
<ng-view></ng-view>
</div>