如何在角度中删除模块未找到错误

如何在角度中删除模块未找到错误

本文介绍了如何在角度中删除模块未找到错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里做了一个简单的控制器示例.

I make a simple example of controller here .

http://plnkr.co/edit/dplJ6sf4kgiwJ5pXu4GE?p=preview

我想测试控制器.我可以在线测试我的控制器

and I want to test the controller .I am able to test my controller online

这是我在线测试控制器的代码http://plnkr.co/edit/xzvhXHPoUdulOM9clOkQ?p=preview

Here is my code to test my controller onlinehttp://plnkr.co/edit/xzvhXHPoUdulOM9clOkQ?p=preview

但是当我尝试在我的计算机上运行相同的工作时,我的测试用例失败了我收到错误

But when I try to run that same work on my computer my test case are failI am getting error this

Module 'app.home' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

这是我的计算机代码.https://dl.dropbox.com/s/no901z41bza7osm/SimpleDemo.zip?dl=0

请运行 npm install 添加依赖项.

Please run npm install to add dependency .

这是我的 karma.conf.js 文件

Here is my karma.conf.js file

// Karma configuration
// Generated on Fri Dec 18 2015 19:53:32 GMT+0530 (IST)

module.exports = function(config) {
  config.set({

    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: '',


    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['jasmine'],


    // list of files / patterns to load in the browser
    files: [

        'bower_components/angular/angular.js' ,
        'bower_components/jquery/dist/jquery.js' ,
        'bower_components/angular-ui-router/release/angular-ui-router.js' ,
        'bower_components/angular-mocks/angular-mocks.js' ,
        'bower_components/angular-resource/angular-resource.js' ,


        'app/*.js',
        'app/**/*.js',
        'app/**/*.html',
      'test/**.js'
    ],


    // list of files to exclude
    exclude: [
    ],


    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
        'app/**/*.html':['ng-html2js']
    },

      ngHtml2JsPreprocessor:{
          moduleName:'templates'

    },

    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    reporters: ['progress'],


    // web server port
    port: 9876,


    // enable / disable colors in the output (reporters and logs)
    colors: true,


    // level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_INFO,


    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: true,


    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    browsers: ['Chrome'],


    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: false,

    // Concurrency level
    // how many browser should be started simultanous
    concurrency: Infinity
  })
}

这是我的代码测试

(function(){

    'use strict'
    describe('http controller test', function() {

        var $rootScope,
            $scope,
            controller,
            $q,
            $httpBackend;

        beforeEach(function() {
            module('app');

            inject(function($injector) {
                $rootScope = $injector.get('$rootScope');
                $scope = $rootScope.$new();
                controller = $injector.get('$controller')('homeCntrl', {
                    $scope: $scope
                })


            })
        })




        describe('Init value', function() {
            it('check name value', function() {
                expect(controller.message).toBeUndefined();
            })

        })

        it('it should be true', function() {
            expect(true).toBeTruthy();

        })
    })


})()

任何更新?如何进行控制器测试?

any update ?how to do testing of controller?

更新 1

当我这样写时它不起作用...检查这些文件

when I write like that it is not working ...check these file

'app/**/*.js',
            'app/*.js',
            'app/home/controller/*.js',
            'app/**/*.html',
           'test/**.js'

完整代码

 files: [

        'bower_components/angular/angular.js' ,
        'bower_components/jquery/dist/jquery.js' ,
        'bower_components/angular-ui-router/release/angular-ui-router.js' ,
        'bower_components/angular-mocks/angular-mocks.js' ,
        'bower_components/angular-resource/angular-resource.js' ,




        'app/**/*.js',
        'app/*.js',
        'app/home/controller/*.js',
        'app/**/*.html',
       'test/**.js'
    ],

但是当我这样写的时候它完美地工作,为什么?

but when I write like that it work perfectly why ?

 files: [

        'bower_components/angular/angular.js' ,
        'bower_components/jquery/dist/jquery.js' ,
        'bower_components/angular-ui-router/release/angular-ui-router.js' ,
        'bower_components/angular-mocks/angular-mocks.js' ,
        'bower_components/angular-resource/angular-resource.js' ,




        'app/home/*.js',
        'app/app.js',
        'app/home/controller/*.js',
        'app/**/*.html',
       'test/**.js'
    ],

推荐答案

在你的 route.js 这一行中:controller:'homeCntrl as home'

In your route.js in this line: controller:'homeCntrl as home'

这篇关于如何在角度中删除模块未找到错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 06:10