2017-10-21 43 views
0

J'utilise Angularjs et Jasmine.Comment réparer l'erreur 'Le module n'est pas disponible! Vous avez soit mal orthographié le ... '

je reçois l'erreur suivante:

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) 

my-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> 

my-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); 
    }); 
}); 

SpecRunner.html

<!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> 

Qu'est-ce qui me manque?

Rejeter dessous de cette ligne
[Je vais juste ajouter un peu de charabia ci-dessous afin stackoverflow ne sera pas erreur disant qu'il n'y a pas assez de description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua Ut utim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate vlit esse cillum dolore eu fugiat nulla pariatur. occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim est id laborum. "]

Répondre

1

Deviner. J'ai dû enlever le manuscrit du html et faire un dossier .js séparé.

my-template.js

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

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

my-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 -Ajouter la ligne suivante

... 
<script src="src/my-template.js"></script> 
...