Description :
angular.bootstrap
provide the facility to remove the NG-APP
tag from html. This is the alternate way to enable angular without using ng-app
directive. Here is the code for bootstrap: angular.bootstrap(document, ['app']); See the code snippet:
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Welcome to LearnKode - A code learning platform</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> </head> <body> <div ng-controller="bootstrapController"> {{name}} </div> </body> </html> <script> var app = angular.module("app", []); app.controller('bootstrapController', ['$scope', function ($scope) { $scope.name = "LearnKode"; }]); angular.bootstrap(document, ['app']); </script>
Description :
In this example, we will see the sum of two values val1 and val2 and display the result without using ng-app
directive. See the code snippet:
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Welcome in the AngularJS</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> </head> <body> <div ng-controller="bootstrapController"> <form ng-submit="add()"> <input type="number" ng-model="val1" /> <input type="number" ng-model="val2" /><br /> Sum: {{sum}}<br /> <button>Save</button> </form> </div> </body> </html> <script> var app = angular.module("app", []); app.controller('bootstrapController', ['$scope', function ($scope) { $scope.add = function () { $scope.sum = $scope.val1 + $scope.val2; } }]); angular.bootstrap(document, ['app']); </script>
Description :
Example of Angular bootstrap
:
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Welcome in the AngularJS</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> </head> <body> <div ng-controller="bootstrapController"> <div class="container"> <div class="col-md-3"> Are you developer <input type="checkbox" ng-model="isTrue" ng-change="isTrue==true?count=count+1:null" /> <pre> Count: {{count}}<br />{{isTrue}}</pre> </div> </div> </div> </body> </html> <script> var app = angular.module("app", []); app.controller('bootstrapController', ['$scope', function ($scope) { $scope.isTrue = true; }]); angular.bootstrap(document, ['app']); </script>
Description :
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Welcome in the AngularJS</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> </head> <body> <div ng-controller="bootstrapController"> <div class="container"> <div class="col-md-3 well" ng-init="count=0"> Male: <input type="radio" ng-model="gender" value="Male" ng-change="layout(gender)" /> Female: <input type="radio" ng-model="gender" value="Female" ng-change="layout(gender)" /> <pre><b>Changed</b> {{result}} </pre> </div> </div> </div> </body> </html> <script> var app = angular.module("app", []); app.controller('bootstrapController', ['$scope', function ($scope) { $scope.layout = function (gender) { $scope.result = gender; } }]); angular.bootstrap(document, ['app']); </script>