search

Home  >  Q&A  >  body text

angular.js - When using angularjs, why is it reported that controller is not defined?

I just started learning Angular, and when I tried to write a small demo, I got an error. . .

html:

js:

Error report:

------New error message= =#----

Rewritten according to @张博汉's method

Still getting the same error

Then I put ng-app="myApp"

Reported a new error T^T

迷茫迷茫2780 days ago642

reply all(2)I'll reply

  • 高洛峰

    高洛峰2017-05-15 16:52:40

    Cannot be used directlyfunction来定义controller

    var myApp = angular.module('myApp',[]);
    
    myApp.controller('GreetingController', ['$scope', function($scope) {
      $scope.greeting = 'Hola!';
    }]);
    

    Reference: https://docs.angularjs.org/guide/controller


    Holdng-app改成ng-app="myApp"ah, dear

    reply
    0
  • PHPz

    PHPz2017-05-15 16:52:40

    How did the original poster solve the problem? Urgent, waiting online

    reply
    0
  • Cancelreply