【问题标题】:Angular unknown provider error角度未知提供程序错误
【发布时间】:2014-08-26 01:56:40
【问题描述】:

我在运行 grunt serve 时遇到了 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 serve 后出现的错误:

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

【问题讨论】:

标签: javascript angularjs yeoman


【解决方案1】:

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

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

例如

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

参考在 Angular Phonecat 教程的 5th step 中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-11
    • 2015-03-28
    • 2013-07-07
    • 2015-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多