YouTip LogoYouTip

Angularjs Application

* * * Now it's time to create a real AngularJS single-page web application (SPA). * * * ## AngularJS Application Example You have learned enough about AngularJS to start creating your first AngularJS application: ## My Notes Remaining characters: **100** * * * ## Application Explanation ## AngularJS Example

My Notes

Number of characters left:

[Try it Β»](#) Application file "myNoteApp.js": var app = angular.module("myNoteApp", []); Controller file "myNoteCtrl.js": app.controller("myNoteCtrl", function($scope) { $scope.message = ""; $scope.left = function() {return 100 - $scope.message.length;}; $scope.clear = function() {$scope.message = "";}; $scope.save = function() {alert("Note Saved");}; }); The element is the container for the AngularJS application: ng-app="**myNoteApp**": The
is the scope for the controller in the HTML page: ng-controller="**myNoteCtrl**":
The **ng-model** directive binds the The two **ng-click** events call the controller functions **clear()** and **save()**: The **ng-bind** directive binds the controller function **left()** to the to display the remaining characters: Number of characters left: The application library files need to execute after AngularJS has loaded: * * * ## AngularJS Application Architecture The example above is a complete AngularJS single-page web application (SPA). The element contains the AngularJS application (**ng-app=**). The
element defines the scope for the AngularJS controller (**ng-controller=**). An application can have many controllers. The application file (**my...App.js**) defines the application model code. One or more controller files (**my...Ctrl.js**) define the controller code. * * * ## Summary - How Does It Work? The ng-app directive is located at the root of the application. For a single-page web application (SPA), the root of the application is typically the element. One or more ng-controller directives define the application's controllers. Each controller has its own scope: the defined HTML elements. AngularJS starts automatically when the HTML DOMContentLoaded event occurs. If the ng-app directive is found, AngularJS loads the module specified in the directive and compiles the HTML with ng-app as the root of the application. The root of the application can be the entire page, or a small part of the page. If it's a small part, compilation and execution will be faster.
← Angularjs ExamplesAngularjs Modules β†’

YouTip © 2024-2026 | Home | Learn Technology, Build Dreams!

All content is for educational and learning purposes only.