Angularjs Getting Started
What is Angularjs
AngularJS Is a modern the JavaScript framework from Google commonly used to work with single Page applications (SPAs). AngularJS is open sourced under MIT License and the development progress of AngularJS can followed on its GitHub re Pository. The library is called Angular because HTML uses Angular brackets.
AngularJS is isn't a DOM manipulation library like jquery but it uses a subset of jquery called Jqlite. AngularJS is primarily based on declarative HTML attributes so can add to your HTML tags. You can try AngularJS in your browser using the Code School website.
Version 1.3.x is the current stable version and the Angular team are working towards a big rewrite of AngularJS for V2.0 wh Ich is currently still in development. This article focuses in Angular 1.X with some notes on where Angular are heading with 2.0.
How to use
New Project
Project structure
Installation
Open Bower.js, add dependencies
" Angular":"1.3.15",
Using gulp, generate files in the Wwwroot/lib directory:
In Gulpfile.js, add the following:
In the task run manager, run:
To add a reference to the _layout.cshtml:
Component
Directives
Add directives.cshtml:
To add a method in HomeControl.cs:
Access:
/home/directives
Https://docs.angularjs.org/api/ng/directive
DataBinding
HomeController.cs
Run:
Templates
HomeController.cs
Operation Result:
Update your changes in real time.
Expressions
Run results
Repeaters
Run results
$scope
Learn more on Scopes in AngularJS
Models
Defined:
var personapp = angular.module (' Personapp ', []);
Use:
<bodyng-app="personApp">
Controllers
Defined:
Use:
Services
Use Services
Run results
Using services to talk to a REST endpoint
To create a new file under the Wwwroot/app directory:
Personapp.js
Personfactory.js
Personcontroller.js
New model
New PersonController
New View
Run results
John Papa ' s Angular Style Guide
Routing and multiple views
Installation of Angular-route:
1, add support for Angular-route in Gulpfile.js.
2. Run the task Manager.
3 to see if the wwwroot/lib is generated.
Use
- New Personmodule.js
2, new personroutes.js
3, new personlist.html,persondetail.html
4, New personlistcontroller.js, Persondetailcontroller.js
5 , New View route.cshtml
PersonController.cs added in:
Run results
Code:
Https://github.com/aspnet/Docs/tree/master/aspnet/client-side/angular/sample/src
Event handlers
- New Eventhandlercontroller.js
- New View event.cshtml
Add in 3,personcontroller.cs
Operation Result:
Clicking on the Say Name button will pop up the box.
Angular 2.0
The next version.
Related resources:
- Angular Docs
- Angular 2 Info
Angularjs Getting Started