2017-10-21 3 views
0

私はAngularjsとJasmineを使用しています。エラーを修正するには 'モジュールは利用できません!あなたはどちらかと間違っていた。 '

Error: [$injector:modulerr] Failed to instantiate module myApplication due to: 
    Error: [$injector:nomod] Module 'myApplication' 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. 
    http://errors.angularjs.org/1.4.4/$injector/nomod?p0=myApplication 
     at file:///Users/Documents/angularjs/code/src/lib/scripts/1_4_4/angular.js:68:12 
... 
TypeError: Cannot read property 'amount' of undefined 
    at UserContext.<anonymous> (file:///Users/Documents/angularjs/code/spec/tests/index_09_controller.spec.js:13:23) 

私-template.html

<html ng-app="myApplication"> 

<head> 
    <script src="lib/scripts/1_4_4/angular.min.js"></script> 
</head> 

<body> 
    <div ng-controller="SimpleController"> 
     {{amount.length}} 
    </div> 

    <script> 
     var myModule = angular.module('myApplication', []); 

     myModule.controller('SimpleController', function($scope) { 
       $scope.amount = ['a','b','c']; 
     }); 
    </script> 
</body> 

</html> 

私-template.spec.js

describe('a simple controller', function(){ 
    var $scope; 

    //See API angular.mock.module 
    beforeEach(module('myApplication')); 

    beforeEach(inject(function($rootScope, $controller){ 
     $scope = $rootScope.$new(); 
     $controller('SimpleController',{$scope : $scope}); 
    })); 

    it('test scope amount', function(){ 
     expect($scope.amount.length).toBe(3); 
    }); 
}); 

<!DOCTYPE html> 
<html> 
<head> 
    <meta charset="utf-8"> 
    <title>Jasmine Spec Runner v2.8.0</title> 

    <link rel="shortcut icon" type="image/png" href="lib/jasmine-2.8.0/jasmine_favicon.png"> 
    <link rel="stylesheet" href="lib/jasmine-2.8.0/jasmine.css"> 

    <script src="lib/jasmine-2.8.0/jasmine.js"></script> 
    <script src="lib/jasmine-2.8.0/jasmine-html.js"></script> 
    <script src="lib/jasmine-2.8.0/boot.js"></script> 
    <script src="src/lib/scripts/1_4_4/angular.js"></script> 
    <script src="src/lib/scripts/1_4_4/angular-mocks.js"></script> 

    <!-- include source files here... --> 
    <script src="src/my-template.html"></script> 

    <!-- include spec files here... --> 
    <script src="spec/tests/my-template.spec.js"></script> 

</head> 

<body> 
</body> 
</html> 
SpecRunner.html:

は、私は次のエラーを取得します

私は何が欠けていますか?このライン
[私はちょうどので、stackoverflowのに十分な説明がないというエラーはありません下にいくつかちんぷんかんぷんを追加するつもりだ下記

破棄:「Loremのイプサム嘆きAMET座る、consectetur adipiscing ELIT、あなたの欲求を満たしているかどうかを確認してください。あなたの欲求が満たされているかどうかを確認してください。オバマ大統領の非公式会見で、非公式のカップピタートを抱えていた。 "]

答えて

1

理解した。私はHTMLからスクリプトを削除し、別の.jsファイルを作成しなければならなかった。

私-template.js

var myModule = angular.module('myApplication', []); 

myModule.controller('SimpleController', function($scope) { 
     $scope.amount = ['a','b','c']; 
}); 

私-template.html

<html ng-app="myApplication"> 

<head> 
    <script src="lib/scripts/1_4_4/angular.min.js"></script> 
    <script src="my-template.js"></script> 
</head> 

<body> 
    <div ng-controller="SimpleController as ctrl"> 
     {{amount.length}} 
    </div> 
</body> 

</html> 

SpecRunner.html -Add次の行

... 
<script src="src/my-template.js"></script> 
... 
関連する問題