gpt4 book ai didi

javascript - Angular Directive(指令)未知提供者有一些错误

转载 作者:行者123 更新时间:2023-11-30 16:42:14 25 4
gpt4 key购买 nike

我在使用指令时出错,它是否在模块中重复?
我想在许多模板中使用指令 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 抛出错误:

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 <

可以告诉我如何解决吗?

最佳答案

从这里删除 $scope

.directive('hackedNav', ['$scope', '$stateParams', function($scope,$stateParams)

.directive('hackedNav', [function()

移除

controller: function ($scope, $stateParams) {$scope.eventId = $stateParams.eventId;}

To

controller:customController

你的 Controller

.controller('customController',['$scope','$stateParams',function($scope,$stateParams){'use strict';}])

关于javascript - Angular Directive(指令)未知提供者有一些错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31778850/

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