by Julia Dizhak
AngularJS is a Javascript MVC framework, written entirely in JavaScript.
It was created by Google, they put a lot of attention to build nice/properly architecture and maintainable web applications
AngularJS works with the long-established technologies of the web (HTML, CSS, and JavaScript) to make the development of web apps easier and faster than ever before
Model View Controller is a software design pattern that separates representation from user interaction. Model consists of application data and functions that interact with it, while the view presents this data to the user; the controller operates between the two.
Directives could be custom HTML elements and attributes, and class names, as well as comments in AngularJS.
This is a method of creating new HTML elements that they have own custom functionality.
<html ng-app>
Only one ng-app directive can be used per HTML document
Docs https://docs.angularjs.org/api/ng/directive
The most common and widely used are
With the ng-model directive you can bind the value of an input field to a variable created in AngularJS
https://docs.angularjs.org/api/ng/directive/ngModel
<input ng-model="name" placeholder="Your name”>
<h1>Hello {{ name }}</h1>
As soon as we changed the model called name expression in html will be also changed
Ng-model is a key to a concept named as Two-way data binding
2 way in this context means that if the view changes the value, the model observes the change. And if the model changes the value, the view update with the change.
Expressions which allow to insert dynamic values into HTML
<html ng-app>
<body>
<div> {{ 4 + 6 }} </div>
<div> {{ “Angular” + “JS” }} </div>
<div> {{ numberOfRooms() }} </div>
</body>
</html>
In AngularJS, applications are structured in modules
You can define a new module very easily thanks to the function “module’ and then assign inside html template
var app = angular.module(’myApp’, [ ] );
<html ng-app=“myApp">
Declaring the ng-controller attribute on a DOM element says that all of the elements inside of it belong to the controller and will be managed
The controller function takes one or more arguments. $scope object is available on the element and the controller
{{ name }} - not managed by controller
<div ng-controller=‘MyController'>
<input ng-model="name" placeholder="Your name">
<h1>Hello {{ name }}</h1>
</div>
The $scope object is simply a JavaScript object whose properties are all available to the view and with which the controller can interact.
$scope will be the bridge by which we’ll communicate from the controller to the view.
Directive is a HTML annotations that trigger JS behaviors
Typically HTML only tells you about structure, it doesn’t tell you what you application does.
Directives can also be used for:
Directives allow you to write better HTML
<product-title></product-title>
app.directive('productTitle', function() {
return {
restrict: 'E',
templateUrl: 'includes/product_title.html'
};
});
change the way your expressions are displayed
Usage: {{ expression | filter }}
Angular comes with a collection of filters that can change the way your data are displayed https://docs.angularjs.org/api/ng/filter
You can create you own filter
https://docs.angularjs.org/api/ng/filter/date
Formats date to a string based on the requested format.
Edit in Plunker<span>{{1288323623006 | date:"MM/dd/yyyy 'at' h:mma"}}</span>
10/29/2010 @ 5:40AM
https://docs.angularjs.org/api/ng/filter/uppercase
Converts string to uppercase.
user.name = 'Julia Dizhak';
<div>{{user.name | uppercase}}</div>
<div>JULIA DIZHAK</div>
Single Page Application is a webpage that always keeps you on the same page.
On most websites whenever you click a link, the page reloads.
In a single page application, clicking a link keeps you on the same page, but replaces a part of it with the new content.
Examples are things like Mailing systems where you stay on the same page but it just grabs data from pre-loaded stuff.
The ngRoute module helps your application to become a Single Page Application.
If you want to navigate to different pages in your application, but you also want the application to be a SPA, with no page reloading, you can use the ngRoute module.
To make your applications ready for routing, you must include the AngularJS Route module:
<script src="//apis.com/angular/angular-route.js"></script>
Then you must add the ngRoute as a dependency in the application module:
var app = angular.module("myApp", ["ngRoute”]);
Now your application has access to the route module, which provides the $routeProvider
Use the $routeProvider to configure different routes in your application:
full exampleapp.config(function($routeProvider) {
$routeProvider
.when("/", {
templateUrl : "main.htm"
})
.when("/red", {
templateUrl : "red.htm"
})
Your application needs a container to put the content provided by the routing.
This container is the ng-view directive
<div ng-view> </div>
<ng-view> </ng-view>
<div class="ng-view"> </div>
Applications can only have one ng-view directive, and this will be the placeholder for all views provided by the route.
Gulp A JavaScript task runner, designed to automate (run) common tasks
gulp.task('css-compile', function () {
return gulp.src('mmp/static/sass/**/*.scss')
.pipe(debug({title: ‘unicorn:'}))
.pipe(autoprefixer({ browsers: ['last 5 versions', 'IE 9', 'iOS >= 8'] }))
.pipe(cleanCss({ compatibility: 'i18'}))
.pipe(rename(function (path) { path.basename += ".min”; }))
.pipe(gulp.dest(config.paths.css));
});
Node.js a JavaScript runtime environment.
Node Package Manager is a package manager that allows you to install JavaScript libraries that run on node.js
Node Package Manager is a package manager that allows you to install JavaScript libraries that run on node.js
npm init . -> create package.json
npm install gulp (-g) - installs gulp into node_modules or globally
Bower is a package manager for JavaScript and CSS libraries that run in the browser
Package manager for the front-end
bower init . -> create bower.json
bower install jquery --save
bower install angular --save