gpt4 book ai didi

javascript - Angular 未知提供者错误

转载 作者:行者123 更新时间:2023-11-30 12:37:51 25 4
gpt4 key购买 nike

我在运行 grunt serve 时遇到了 angular 和 yeoman 的问题,它缩小了我的 angular 应用程序并将其输出到我的 dist 目录以进行生产。在我的本地主机上运行我的应用程序时,一切似乎都运行良好,但是在构建之后发生了一些我目前还不清楚的事情。任何帮助将不胜感激。

这是我在项目中引入的导致问题的 Controller :

var myPlayer

angular.module('myapp')
.controller('ShowCaseTabCtrl', function ($scope) {
$scope.tabs = [
{
title:"Video",
content:'templates/showcased-video.html',
},
{
title:"Gallery",
content:'templates/showcased-gallery.html',
}
];
// here I am firing this method on ng-include onload to ensure video js
// is being properly instantiated
$scope.initVideo = function() {
videojs('showcase-video', {
'controls': true,
'autoplay': false,
'preload': 'auto',
'poster': 'images/posters/poster.jpg'
}, function(){
myPlayer = this;
myPlayer.dimensions(900, 600);
myPlayer.poster('images/posters/poster.jpg');
myPlayer.src([
{ type: 'video/mp4', src: 'video/myvideo.mp4' },
{ type: 'video/ogg', src: 'video/myvideo.ogv' }
]);
});

}
});

这是我对上面 Controller 的看法:

<section ng-controller="ShowCaseTabCtrl">
<div class="mod-wrap full-bleed">
<tabset>
<tab ng-repeat="tab in tabs" heading="{{tab.title}}" content="{{tab.content}}" active="tab.active">
<ng-include src="tab.content" onload="initVideo()"></ng-include>
</tab>
</tabset>
</div>

从 yo-angular 生成器运行 grunt serve 后出现错误:

Error: [$injector:unpr] Unknown provider: aProvider <- a

最佳答案

原因可能是您的 js 文件被缩小了。

在声明 Controller 、服务和过滤器时尝试使用数组表示法。

例如

controller('ShowCaseTabCtrl', ['$scope', function ($scope) {
// Your code here
}]);

引用在 5th step 的 Angular Phonecat 教程。

关于javascript - Angular 未知提供者错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25496896/

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