Last post Oct 23, 2019 05:39 AM by Yang Shen
Member
84 Points
1323 Posts
Oct 23, 2019 03:51 AM|erum|LINK
i have below code
<html> <head> <title>AngularJS First Application</title> </head> <body> <h1>My First Application</h1> <div ng-app = ""> <p>Enter your Name: <input type = "text" ng-model = "name"></p> <p>Welcome <span ng-bind = "name"></span>!!</p> </div> <script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script> </body> </html>
now i wanted to add any helloworld controller ,provide that ng-app have blank value how can do that ??
Contributor
3140 Points
983 Posts
Oct 23, 2019 05:39 AM|Yang Shen|LINK
Hi erum,
erum now i wanted to add any helloworld controller ,provide that ng-app have blank value how can do that ??
The code you provided is working well, so i guess your requirement is actually about the ealier thread you posted, right?
If so, you can achieve this goal with the $controllerProvider.allowGlobals() to set the controller be used global.
You can refer to Using ng-app without a value, in this thread, it's mentioned that you can use the global controller before Angular 1.3, but in 1.6.4, the $controllerProvider.allowGlobals() is needed.
Also please check AngularJS, allowGlobals for global controllers about how to use this statement.
In your case, you can update your code like this:
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <meta charset="utf-8" /> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script> <script> angular.module("ng").config(function ($controllerProvider) { $controllerProvider.allowGlobals(); }); function FunctionHelloworld($scope) { $scope.message = "ERum"; } </script> </head> <body> <div ng-app ng-controller="FunctionHelloworld"> Hello: {{message}} </div> </body> </html>
However, this $controllerProvider.allowGlobals() is generally not recommended because of namespace related risk.
Best Regard,
Yang Shen
Member
84 Points
1323 Posts
hwo to add controller with empty ng-app vlaue
Oct 23, 2019 03:51 AM|erum|LINK
i have below code
now i wanted to add any helloworld controller ,provide that ng-app have blank value how can do that ??
Contributor
3140 Points
983 Posts
Re: hwo to add controller with empty ng-app vlaue
Oct 23, 2019 05:39 AM|Yang Shen|LINK
Hi erum,
The code you provided is working well, so i guess your requirement is actually about the ealier thread you posted, right?
If so, you can achieve this goal with the $controllerProvider.allowGlobals() to set the controller be used global.
You can refer to Using ng-app without a value, in this thread, it's mentioned that you can use the global controller before Angular 1.3, but in 1.6.4, the $controllerProvider.allowGlobals() is needed.
Also please check AngularJS, allowGlobals for global controllers about how to use this statement.
In your case, you can update your code like this:
However, this $controllerProvider.allowGlobals() is generally not recommended because of namespace related risk.
Best Regard,
Yang Shen