AngularJS - Tutorialspoint

3y ago
201 Views
20 Downloads
538.58 KB
21 Pages
Last View : 4d ago
Last Download : 3m ago
Upload by : Javier Atchley
Transcription

I

AngularJSAbout the TutorialAngularJS is a very powerful JavaScript library. It is used in Single Page Application(SPA) projects. It extends HTML DOM with additional attributes and makes it moreresponsive to user actions. AngularJS is open source, completely free, and used bythousands of developers around the world. It is licensed under the Apache licenseversion 2.0.AudienceThis tutorial is designed for software professionals who want to learn the basics ofAngularJS and its programming concepts in simple and easy steps. It describes thecomponents of AngularJS with suitable examples.PrerequisitesYou should have a basic understanding of JavaScript and any text editor. As we aregoing to develop web-based applications using AngularJS, it will be good if you havean understanding of other web technologies such as HTML, CSS, AJAX, etc.Disclaimer & Copyright Copyright 2014 by Tutorials Point (I) Pvt. Ltd.All the content and graphics published in this e-book are the property of TutorialsPoint (I) Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy,distribute or republish any contents or a part of contents of this e-book in anymanner without written consent of the publisher.We strive to update the contents of our website and tutorials as timely and asprecisely as possible, however, the contents may contain inaccuracies or errors.Tutorials Point (I) Pvt. Ltd. provides no guarantee regarding the accuracy, timelinessor completeness of our website or its contents including this tutorial. If you discoverany errors on our website or in this tutorial, please notify us atcontact@tutorialspoint.comi

AngularJSTable of ContentsAbout the Tutorial iAudience iPrerequisites iDisclaimer & Copyright iTable of Contents ii1.OVERVIEW 1General Features 1Core Features 1Concepts 2Advantages of AngularJS 3Disadvantages of AngularJS 4AngularJS Directives 42.ENVIRONMENT 53.MVC ARCHITECTURE 9The Model 10The View 10The Controller 104.FIRST APPLICATION 11Creating AngularJS Application 11Executing AngularJS Application 11How AngularJS Integrates with HTML 135.DIRECTIVES 14ng-app directive 14ng-init directive 14ng-model directive 15ii

AngularJSng-repeat directive 156.EXPRESSIONS 177.CONTROLLERS 198.FILTERS 22Uppercase Filter 22Lowercase Filter 22Currency Filter 22Filter 23OrderBy Filter 239.TABLES 2710. HTML DOM 31ng-disabled Directive 31ng-show Directive 31ng-hide Directive 31ng-click Directive 3211. MODULES 34Application Module 34Controller Module 34Use Modules 3512. FORMS 39Events 39ng-click 39Validate Data 4013. INCLUDES 4414. AJAX 48iii

AngularJS15. VIEWS 52ng-view Directive 52ng-template Directive 52 routeProvider Service 5316. SCOPES 57Scope Inheritance 5717. SERVICES 61Using Factory Method 61Using Service Method 6118. DEPENDENCY INJECTION 64Value 64Factory 65Service 65Provider 66Constant 6719. DIRECTIVES 70ng-app directive 70ng-init directive 70ng-model directive 71ng-repeat directive 7120. INTERNALIZATION 73Example Using Danish Locale 73Example Using Browser Locale 74iv

1. OVERVIEWAngularJSAngularJS is an open-source web application framework. It was originally developedin 2009 by Misko Hevery and Adam Abrons. It is now maintained by Google. Its latestversion is 1.2.21.Definition of AngularJS as put by its official documentation is as follows:AngularJS is a structural framework for dynamic web applications. It lets youuse HTML as your template language and lets you extend HTML's syntax toexpress your application components clearly and succinctly. Its data bindingand dependency injection eliminate much of the code you currently have towrite. And it all happens within the browser, making it an ideal partner with anyserver technology.General FeaturesThe general features of AngularJS are as follows: AngularJS is a efficient framework that can create Rich Internet Applications(RIA). AngularJS provides developers an options to write client side applications usingJavaScript in a clean Model View Controller (MVC) way. Applications written in AngularJS are cross-browser compliant. AngularJSautomatically handles JavaScript code suitable for each browser. AngularJS is open source, completely free, and used by thousands ofdevelopers around the world. It is licensed under the Apache license version2.0.Overall, AngularJS is a framework to build large scale, high-performance, and easyto-maintain web applications.Core FeaturesThe core features of AngularJS are as follows: Data-binding: It is the automatic synchronization of data between model andview components.v

AngularJS Scope: These are objects that refer to the model. They act as a glue betweencontroller and view. Controller: These are JavaScript functions bound to a particular scope. Services: AngularJS comes with several built-in services such as http tomake a XMLHttpRequests. These are singleton objects which are instantiatedonly once in app. Filters: These select a subset of items from an array and returns a new array. Directives: Directives are markers on DOM elements such as elements,attributes, css, and more. These can be used to create custom HTML tags thatserve as new, custom widgets. AngularJS has built-in directives such asngBind, ngModel, etc. Templates: These are the rendered view with information from the controllerand model. These can be a single file (such as index.html) or multiple views inone page using partials. Routing: It is concept of switching views. Model View Whatever: MVW is a design pattern for dividing an applicationinto different parts called Model, View, and Controller, each with distinctresponsibilities. AngularJS does not implement MVC in the traditional sense,but rather something closer to MVVM (Model-View-ViewModel). The AngularJS team refers it humorously as Model View Whatever. Deep Linking: Deep linking allows to encode the state of application in theURL so that it can be bookmarked. The application can then be restored fromthe URL to the same state. Dependency Injection: AngularJS has a built-in dependency injectionsubsystem that helps the developer to create, understand, and test theapplications easily.ConceptsThe following diagram depicts some important parts of AngularJS which we willdiscuss in detail in the subsequent chapters.vi

AngularJSAdvantages of AngularJSThe advantages of AngularJS are: It provides the capability to create Single Page Application in a very clean andmaintainable way. It provides data binding capability to HTML. Thus, it gives user a rich andresponsive experience. AngularJS code is unit testable. AngularJS uses dependency injection and make use of separation of concerns. AngularJS provides reusable components.vii

AngularJS With AngularJS, the developers can achieve more functionality with short code. In AngularJS, views are pure html pages, and controllers written in JavaScriptdo the business processing.On the top of everything, AngularJS applications can run on all major browsers andsmart phones, including Android and iOS based phones/tablets.Disadvantages of AngularJSThough AngularJS comes with a lot of merits, here are some points of concern: Not secure : Being JavaScript only framework, application written inAngularJS are not safe. Server side authentication and authorization is mustto keep an application secure. Not degradable: If the user of your application disables JavaScript, thennothing would be visible, except the basic page.AngularJS DirectivesThe AngularJS framework can be divided into three major parts: ng-app : This directive defines and links an AngularJS application to HTML. ng-model : This directive binds the values of AngularJS application data toHTML input controls. ng-bind : This directive binds the AngularJS application data to HTML tags.viii

2. ENVIRONMENTAngularJSThis chapter describes how to set up AngularJS library to be used in web applicationdevelopment. It also briefly describes the directory structure and its contents.When you open the link https://angularjs.org/, you will see there are two options todownload AngularJS library: View on GitHub – By clicking on this button, you are diverted to GitHub andget all the latest scripts. Download – By clicking on this button, a screen you get to see a dialog boxshown as:ix

AngularJSThis screen offers various options for selecting Angular JS as follows: Downloading and hosting files locallyoThere are two different options : Legacy and Latest. The namesthemselves are self-descriptive. The Legacy has version less than 1.2.xand the Latest come with version 1.3.x.oWe can also go with the minimized, uncompressed, or zipped version.CDN access: You also have access to a CDN. The CDN gives you access toregional data centers. In this case, the Google host. The CDN transfers theresponsibility of hosting files from your own servers to a series of externalones. It also offers an advantage that if the visitor of your web page hasalready downloaded a copy of AngularJS from the same CDN, there is no needto re-download it.We are using the CDN versions of the library throughout this tutorial.ExampleNow let us write a simple example using AngularJS library. Let us create an HTML filemyfirstexample.html shown as below: !doctype html html x

AngularJS head script src .3.0beta.17/angular.min.js" /script /head body ng-app "myapp" div ng-controller "HelloController" h2 Welcome {{helloTo.title}} to the world of Tutorialspoint! /h2 /div script angular.module("myapp", []).controller("HelloController", function( scope) { scope.helloTo {}; scope.helloTo.title "AngularJS";}); /script /body /html Let us go through the above code in detail:Include AngularJSWe include the AngularJS JavaScript file in the HTML page so that we can use it: head scriptsrc 2.15/angular.min.js" /script /head You can check the latest version of AngularJS on its official website.Point to AngularJS appNext, it is required to tell which part of HTML contains the AngularJS app. You can dothis by adding the ng-app attribute to the root HTML element of the AngularJS app.You can either add it to the html element or the body element as shown below:xi

AngularJS body ng-app "myapp" /body ViewThe view is this part: div ng-controller "HelloController" h2 Welcome {{helloTo.title}} to the world of Tutorialspoint! /h2 /div ng-controller tells AngularJS which controller to use with this view. helloTo.title tellsAngularJS to write the model value named helloTo.title in HTML at this location.ControllerThe controller part is: script angular.module("myapp", []).controller("HelloController", function( scope) { scope.helloTo {}; scope.helloTo.title "Angul

AngularJS uses dependency injection and make use of separation of concerns. AngularJS provides reusable components. AngularJS viii With AngularJS, the developers can achieve more functionality with short code. In AngularJS, views are pure html pages, and controllers written in JavaScript do the business processing. On the top of everything, AngularJS applications can run on all major browsers .

Related Documents:

AngularJS Tutorial W3SCHOOLS.com AngularJS extends HTML with new attributes. AngularJS is perfect for Single Page Applications (SPAs). AngularJS is easy to learn. This Tutorial This tutorial is specially designed to help you learn AngularJS as quickly and efficiently as possible. First, you will learn the basics of AngularJS: directives, expressions, filters, modules, and controllers. Then you .

Beginning AngularJS Beginning AngularJS is your step-by-step guide to learning the powerful AngularJS JavaScript framework. AngularJS is one of the most respected and innovative frameworks for building properly structured, easy-to-develop web applications. This book will teach you the absolute essentials, from downloading and installing AngularJS, to using modules, controllers, expressions .

AngularJS provides data binding capability to HTML thus giving user a rich and responsive experience AngularJS code is unit testable. AngularJS uses dependency injection and make use of separation of concerns. AngularJS provides reusable components. With AngularJS,

AngularJS Tutorial, AngularJS Example pdf, AngularJS, AngularJS Example, angular ajax example, angular filter example, angular controller Created Date 11/29/2015 3:37:05 AM

AngularJS team at Google as an external contractor and is a founder member of the AngularUI project. He has spoken about AngularJS at Devoxx UK and numerous London meetups. He also runs training courses in AngularJS. His consultancy practice is now primarily focused on helping businesses make best use of AngularJS. I would like to thank the team at Google for giving us AngularJS, in particular .

Code Explanation for ng-transclude Directive in AngularJS: 1. The ng-app specifies the root element ( myApp ) to define AngularJS . ng-transclude directive is used to include the existing content "AngularJS" . Sample Output for ng-transclude Directive in AngularJS: 1. The content welcome to wikitechy is displayed in the output using the .

AngularJS is a JavaScript framework. It is a library written in JavaScript. AngularJS is distributed as a JavaScript file, and can be added to a web page with a script tag: [3] AngularJS extends HTML with ng-directives. The ng-app directive defines that this is an AngularJS application.

Engineering Graphics & Design (EGD) NOTE: Information as on 15 November 2020. ENGINEERING GRAPHICS AND DESIGN. GRADE 10 . GRADE 11; GRADE 12 . General drawing principles: Use/care/dangers of drawing instruments, line types, line work, lettering, dimensioning etc. The Grade 10 contentremains applicable. The Grade 10 contentremains applicable. Free-hand drawing. Free-hand drawing techniques. The .