我使用指令时出错,是否在模块中重复?
我想在许多模板中使用指令hacked-nav
,
我会在许多模块中写hacked-nav
,
这个错误是指令名称重复吗?
的index.html:
<hacked-nav></hacked-nav> //this is directive
app.js:
angular.module('monitor')
.controller('hackMonitorCtr',['$scope', function($scope){
┊'use strict';
}])
.directive('scatterChart', function () {
return {
┊ restrict: 'E',
┊ scope: false,
┊ template:'<div style="width: 50%; height: 100%; float: left;"></div>',
┊ replace:true,
┊ link:function(scope,element,attrs){
┊ ┊ require([
┊ ┊ ┊ 'echarts',
┊ ┊ ┊ 'ChartFactory',
┊ ┊ ┊ 'echarts/chart/scatter',
┊ ┊ ┊ ],
┊ ┊ ┊ function(ec,ChartFactory){
┊ ┊ ┊ ┊ var scatterDom = ec.init(element[0]);
┊ ┊ ┊ ┊ ChartFactory.create('scatter', null, null, scatterDom);
┊ ┊ ┊ });
┊ }
};
})
.directive('hackedNav', ['$scope', '$stateParams', function($scope, $stateParams) {
return {
┊ restrict: 'E',
┊ replace: true,
┊ scope: true,
┊ templateUrl: 'client/app/modules/monitor/templates/hacked-nav.ng.html',
┊ controller: function ($scope, $stateParams) {
┊ ┊ $scope.eventId = $stateParams.eventId;
┊ }
};
}]);
入侵-nav.ng.html
<ul>
<li class="nav">
┊ <a href="/monitors/{{ eventId }}"><img src="pic/composite.png" /></a>
┊ <span>综合信息</span>
</li>
<li class="nav">
┊ <a href="/hackmonitor/{{ eventId }}"><img src="pic/hacked.png"></a>
┊ <span>被黑监控</span>
</li>
<li class="nav">
┊ <a href="/leakmonitor/{{ eventId }}"><img src="pic/leak.png"></a>
┊ <span>漏洞监控</span>
</li>
<li class="nav">
┊ <a href="/webperformance/{{ eventId }}"><img src="pic/monitor.png"></a>
┊ <span>性能监控</span>
</li>
<li class="nav">
┊ <a href="/webdisposition/{{ eventId }}"><img src="pic/disposition.png"></a>
┊ <span>处置情况</span>
</li>
</ul>
chrmoe throw错误:
Error: [$injector:unpr] Unknown provider: $scopeProvider <- $scope <- hackedNavDirective
http://errors.angularjs.org/1.4.2/$injector/unpr?p0=%24scopeProvider%20%3C-%20%24scope%20%3C-%20hackedNavDirective
at REGEX_STRING_REGEXP (angular.js:68)
at angular.js:4264
at Object.getService [as get] (angular.js:4411)
at angular.js:4269
at getService (angular.js:4411)
at Object.invoke (angular.js:4443)
at angular.js:6943
at forEach (angular.js:336)
at Object.<anonymous> (angular.js:6941)
at Object.invoke (angular.js:4452)(anonymous function) @ angular.js:12332$get @ angular.js:9111(anonymous function) @ angular.js:6962forEach @ angular.js:336(anonymous function) @ angular.js:6941invoke @ angular.js:4452enforcedReturnValue @ angular.js:4305invoke @ angular.js:4452(anonymous function) @ angular.js:4270getService @ angular.js:4411addDirective @ angular.js:8210collectDirectives @ angular.js:7591compileNodes @ angular.js:7457compileNodes @ angular.js:7473compileNodes @ angular.js:7473compile @ angular.js:7368compile @ angular-ui-router.js:4013invokeLinkFn @ angular.js:8652nodeLinkFn @ angular.js:8152compositeLinkFn @ angular.js:7543publicLinkFn @ angular.js:7418updateView @ angular-ui-router.js:3959(anonymous function) @ angular-ui-router.js:3921$get.Scope.$broadcast @ angular.js:16167$state.transitionTo.$state.transition.resolved.then.$state.transition @ angular-ui-router.js:3311processQueue @ angular.js:14569(anonymous function) @ angular.js:14585$get.Scope.$eval @ angular.js:15848$get.Scope.$digest @ angular.js:15659$get.Scope.$apply @ angular.js:15953bootstrapApply @ angular.js:1633invoke @ angular.js:4452doBootstrap @ angular.js:1631bootstrap @ angular.js:1651angularInit @ angular.js:1545(anonymous function) @ angular.js:28361jQuery.Callbacks.fire @ jquery.js:3143jQuery.Callbacks.self.fireWith @ jquery.js:3255jQuery.extend.ready @ jquery.js:3467completed @ jquery.js:3498
scatter.js:1 Uncaught SyntaxError: Unexpected token <
可以告诉我如何解决它?
答案 0 :(得分:2)
从此处删除$ scope
.directive('hackedNav', ['$scope', '$stateParams', function($scope,$stateParams)
要
.directive('hackedNav', [function()
和
删除
controller: function ($scope, $stateParams) {$scope.eventId = $stateParams.eventId;}
To
controller:customController
你的控制器
.controller('customController',['$scope','$stateParams',function($scope,$stateParams){'use strict';}])