search

Home  >  Q&A  >  body text

angular.js - AngularJS's Controller (HelloAngular) does not take effect and cannot get the value

<html ng-app>
<head>Angular Model</head>
<body>

<p>
    <input ng-model="greeting.text"/>
    <p>{{greeting.text}}, AngularJS</p>
</p>
<p ng-controller="HelloAngular">
    <p>{{greetingCon.text}}, AngularJS</p>
</p>

</body>
<script src="js/angular.js"></script>
<script src="js/HelloAngular_MVC.js"></script>
</html>

function HelloAngular($scope){

$scope.greetingCon = {
    text: 'Hello'
};

}

世界只因有你世界只因有你2750 days ago754

reply all(2)I'll reply

  • 过去多啦不再A梦

    过去多啦不再A梦2017-06-10 09:50:09

    var app = angular.module("myApp", []);
    app.controller("HelloAngular", ['$scope', function($scope) {
      $scope.greetingCon = {
        text: 'Hello'
      };
    }])

    Try to see if you can get the value

    reply
    0
  • 高洛峰

    高洛峰2017-06-10 09:50:09

    Because your current writing method can run before 1.3.0. If your Angular version is after 1.3.0-beta.15, writing this way will not work.

    Here is the official changelog, the description has been selected: https://github.com/angular/an...

    Therefore, you need to mount controller under a module

    It is also mentioned that you can add $controllerProvider.allowGlobals(); to config to allow global function, but it is not recommended

    reply
    0
  • Cancelreply