简体   繁体   中英

Why doesn't my variable render in my view after populating it in my controller?

What am I doing wrong? angular.min.js is in the folder js . I am using the book from O'Reilly. There is an example like this. But on my PC it doesn't work.

 //controller.js function HelloController($scope) { $scope.greeting = { text: 'Hello' }; } 
 <!DOCTYPE html> <html> <head> <script type="text/javascript" src="js/angular.min.js"></script> <script type="text/javascript" src="js/controller.js"></script> </head> <body ng-app=""> <div ng-controller='HelloController'> <p>{{greeting.text}}, World</p> </div> </body> </html> 

  1. I think you are referring to old book. Please update your controller as below

    //controller.js
    var app = angular.module('myApp', []);
    app.controller('HelloController', function($scope) {
    $scope.greeting = { text: 'Hello' };
    });

and in HTML ng-app="myApp"

Please try and let us know whether it is working or not

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM