Problème angularJs

Par shiba, il y a 10 ans


Bonjour,
Je débute avec angularJs et donc pour m'entrainer à l'utiliser j'ai décider de développer mon portfolio avec ce framework.
Je rencontre une erreur et même en lisant la console, je ne comprend pas.
Voici mon code :

<!doctype html> <html lang="fr" ng-app> <head> <meta charset="utf-8"> <title> Portfolio de Gataf </title> <!----<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css">--> <link rel="stylesheet" href="CSS/portfolio.css"> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script> <!-- <script src="js/directives.js"></script>--> </head> <body> <!--<div ng-background></div>--> <div ng-controller="presentationCtrl"> <div ng-repeat="presentation in presentations"> <p> <strong> {{presentation.phrase}}</strong> </p> </div> </div> <script> function presentationCtrl($scope){ $scope.presentations = [ { 'phrase' : 'Bienvenu sur mon portfolio' }, { 'phrase' : 'Gatien TAFFOREAU' }, { 'phrase' : 'En école d\'ingénieur informatique' } ] } </script> </body> </html>

Et l'erreur retournée est celle-ci [https://docs.angularjs.org/error/ng/areq?p0=presentationCtrl&p1=not%20a%20function,%20got%20undefined]()

16 réponses

Lartak, il y a 10 ans

Bonsoir.
Et le lien que tu nous donnes redirige sur une page de la documentation d'AngularJs, qui explique justement cette erreur :

Argument 'presentationCtrl' is not a function, got undefined
Description
AngularJS often asserts that certain values will be present and truthy using a helper function. If the assertion fails, this error is thrown. To fix this problem, make sure that the value the assertion expects is defined and truthy.

Que veux-tu que nous te disions de plus ?

shiba, il y a 10 ans

Pourquoi angular ne détecte pas ma fonction tandis que je l'ai déclaré comme j'ai pu trouver dans le tutoriel sur ce site.

shiba, il y a 10 ans

Bonsoir, oui j'ai skype. Mais je ne comprend pas bien pourquoi tu veux communiquer via skype?

shiba, il y a 10 ans

Car je ne suis pas familier avec AngularJs, j'apprend à l'utiliser.

shiba, il y a 10 ans

Tu as du texte qui s'affiche à l'écran?

shiba, il y a 10 ans

Tu demandes à tous les gens sur le forum de communiquer avec toi via skype?

shiba, il y a 10 ans

Pour cela tu as les forums.
As tu du texte qui s'affiche à l'écran quand tu utilises mon code?

shiba, il y a 10 ans

Donc cela veut dire que si tu ouvre la console web, tu as une erreur...

shiba, il y a 10 ans

Fais clique droit -> Inspecter l'élèment et ensuite tu affiches la console

shiba, il y a 10 ans

Donc tu vois que tu as des erreurs

Remi Palisse, il y a 10 ans

Trouver comment le résoudre

Remi Palisse, il y a 10 ans

Dans le html il y a le ng-app tu le remplace par

ng-app=myApp
shiba, il y a 10 ans

Ouai j'ai résolu mon problème. Mais tu n'as rien changé d'autre au code?

Remi Palisse, il y a 10 ans

Non je n'est rien changer

Remi Palisse, il y a 10 ans

Ducoup sa mafiche {{presentation.phrase}}

shiba, il y a 10 ans

J'ai trouvé comment résoudre le problème, car en faite la syntaxe des controllers est changé.
[](<!doctype html>

<html lang="fr" ng-app="portfolio">

<head>

    <meta charset="utf-8">

    <title> Portfolio de Gataf </title>

    <!--<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css">-->
    <link rel="stylesheet" href="CSS/portfolio.css">

    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.1/angular.min.js"></script>
    <!-- <script src="js/directives.js"></script>-->

</head>
<body>

    <!--<div ng-background></div>-->

    <div ng-controller="presentationCtrl"> 
        <div ng-repeat="presentation in presentations">
            <p>
                <strong> {{presentation.phrase}}</strong>
            </p>
        </div>  
    </div>

    <script>

        angular.module('portfolio', []).controller('presentationCtrl', function($scope){
            $scope.presentations = [
                {
                    'phrase' : 'Bienvenu sur mon portfolio'
                },
                {
                    'phrase' : 'Gatien TAFFOREAU'
                },
                {
                    'phrase' : 'En école d\'ingénieur informatique'
                }
            ];
        });
    </script>

</body>

</html>)