Angular未知提供商错误

Angular unknown provider error

本文关键字:错误 提供商 未知 Angular      更新时间:2023-09-26

我在运行grunt服务时遇到了angular和yeoman的问题,它会将我的angular应用程序最小化并输出到我的dist目录以用于生产。当在我的本地主机上运行我的应用程序时,一切似乎都很好,但在做了构建之后,正在发生的事情对我来说目前还不清楚。如有任何帮助,我将不胜感激。

这是我在项目中引入的导致问题的控制器:

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' }
            ]);
        });
    }
});

这是我对上面控制器的视图:

<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服务后出现的错误:

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

原因可能是你的js文件被压缩了。

尝试用数组符号来声明你的控制器、服务和过滤器。

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

该引用在Angular Phonecat教程的第5步中。