I wonder why this is a problem with using empty lines for ng-app . In the example provided by w3school, I tried using an empty string to name an ng application, as shown below, but failed.
<!DOCTYPE html> <html> <script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"> </script> <body> <p>Try to change the names.</p> <div ng-app="" ng-controller="myCtrl"> First Name: <input type="text" ng-model="firstName"><br> Last Name: <input type="text" ng-model="lastName"><br> <br> Full Name: {{firstName + " " + lastName}} </div> <script> var app = angular.module('', []); app.controller('myCtrl', function($scope) { $scope.firstName= "John"; $scope.lastName= "Doe"; }); </script> </body> </html>
Even creating a " " will make the ng-app directive. Any ideas?
The reason I was asked this question is because I found out one example that implements the same functions without initializing the controller, and ng-app is an empty string.
<!DOCTYPE html> <html> <script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"> </script> <body> <div ng-app="" ng-init="firstName='John'"> <p>The name is <span ng-bind="firstName"></span></p> </div> </body> </html>
source share