background preloader

Angular.JS

Facebook Twitter

Tough

Simple Authentication for Angular.js App. So, you are building pure client side application that works against REST API. The client and server are completely decoupled and typically deployed separately of each other. API’s have one or another way of authenticating it’s users. It could be some simple flows, like basic authorization or more complex ones as OAuth/OAuth2. But at the very end you have token that placed either as cookie value or HTTP request header parameter. API is then responsible to check the token for validity and if it’s not valid respond with 401. Configure the Routes First we need to have /login router where user is redirected in case of unauthorized access. Authentication Controller and View The authentication controller is simple module. Btw, in likeastore/seismo-dashboard I’ve tried to use the model based on GitHub personal tokens instead of passwords, that simplifies server a bit allowing it to do not store and sessions, hashed passwords etc.

HTTP Interceptor The interceptor implementation itself, AngularJS Tips and Tricks [UPDATED] ☢ DeanSofer.com. These tips were developed in AngularJs v0.10.5 v1.0.1. I'll keep updating this post, so check back often! I've compared a LOT of different javascript frameworks for my company's rewrite, and finally settled on AngularJS because of how rapidly I'm able to produce prototypes. In my opinion, although it's very alpha and fairly lacking on the graphical side, it's excellent for CRUD applications (meaning forms, tables and reports). I'm still trying to lean towards emphasizing reusable widgets and directives instead of just custom-coding everything for your own app. If you are still on the fence take a look at TodoMVC for an excellent unbaised comparison.

Most of these tips have been moved to AngularUI - Go check it out! The companion suite to AngularJS, a collection of work by many AngularJS users with a plethora of useful utilities. Table of Contents Serializing the Form No. If every form control on your page does not have an ng-model then you're doing it wrong. Seriously. Useful $scope Methods.

Issues

Egghead.io - AngularJS - Built-in Filters. Index. There was an error loading this resource. Please try again later. A great way to get introduced to AngularJS is to work through this tutorial, which walks you through the construction of an AngularJS web app. The app you will build is a catalog that displays a list of Android devices, lets you filter the list to see only devices that interest you, and then view details for any device. Follow the tutorial to see how AngularJS makes browsers smarter — without the use of native extensions or plug-ins: See examples of how to use client-side data binding to build dynamic views of data that change immediately in response to user actions.See how AngularJS keeps your views in sync with your data without the need for DOM manipulation.Learn a better, easier way to test your web apps, with Karma and Protractor.Learn how to use dependency injection and services to make common web tasks, such as getting data into your app, easier.

When you finish the tutorial you will be able to: Install Git npm install. AngularJS Sticky Notes Pt 2 – Isolated Scope. Welcome to Part 2 of the AngularJS Sticky Notes series! In this blogpost I am going to talk about “isolated” scope as it relates to directives. Directives are one of the most powerful features of AngularJS and yet it can be one of the most confusing aspects of it as well. I believe that part of what makes directives hard to understand are the nuances surrounding scope. Scope by default inherits from its parent scope, but this may not be desirable behavior, especially if you are building a re-usable widget.

I have prepared an example to illustrate what I am going to be talking about, and you can find it here: You can essentially interact with isolated scope in three ways: 1. You can bind a isolated scope property to a DOM attribute. Important note: I am binding the attribute attributeFoo to a isolated property called isolatedAttributeFoo. If both my isolated property and parent property were attributeFoo, then I would simply have to do this: 2. 3. Directives. Loading... Improve this doc Note: this guide is targeted towards developers who are already familiar with AngularJS basics. If you're just getting started, we recommend the tutorial first. If you're looking for the directives API, we recently moved it to $compile. This document explains when you'd want to create your own directives in your AngularJS app, and how to implement them. What are Directives?

At a high level, directives are markers on a DOM element (such as an attribute, element name, comment or CSS class) that tell AngularJS's HTML compiler ($compile) to attach a specified behavior to that DOM element or even transform the DOM element and its children. Angular comes with a set of these directives built-in, like ngBind, ngModel, and ngView. What does it mean to "compile" an HTML template? Matching Directives Before we can write a directive, we need to know how Angular's HTML compiler determines when to use a given directive. The following also matches ngModel: Edit in Plunker Great! AngularJS and scope.$apply — Jim Hoskins. If you’ve written a non-trivial amount of code in AngularJS, you may have come across the $scope. $apply() method. On the surface, it may seem like just a method you call to get your bindings to update.

But why does it exist? And when do you need to use it? To really understand when to use $apply, it’s good to know exactly why we need to use it, so let’s dive in! JavaScript is Turn Based The JavaScript code we write doesn’t all run in one go, instead it executes in turns. Instead, whenever there is a task that takes some amount of time, such as an Ajax request, waiting for a click event, or setting a timeout, we set up a callback function and finish our current turn. Let’s look at an example JavaScript file: var button = document.getElementById('clickMe'); function buttonClicked () { alert('the button was clicked'); } button.addEventListener('click', buttonClicked); function timerComplete () { alert('timer complete'); } setTimeout(timerComplete, 2000); How do we update bindings?

$scope. Promise-ы в AngularJS. Одной из ключевых составляющих практически любого веб-приложения является взаимодействие с сервером. В больших приложениях это далеко не один запрос. При этом запросы часто необходимо объединять для последовательного или параллельного выполнения, а часто сочетать и то и другое. Кроме того, большие приложения обычно имеют многослойную архитектуру — обертка над RESTFul API => бизнес-сущности => более комплексная бизнес-логика (разбиение условно для примера). И на каждом слое необходимо принять данные в одном формате и передать на следующий слой уже в другом. Вот со всеми этими задачами могут помочь справиться Promise-ы. За подробностями добро пожаловать под кат. Promise-ы предоставляют интерфейс для взаимодействия с объектами, содержащими результат выполнения некоторой операции, время окончания которой неизвестно.

Кроме того, promise-ы можно объединять как для последовательного, так и для параллельного исполнения. Итак, что из себя представляет promise? Что в AngularJS вернет вам promise? JavaScript Promises. No I am not talking the promise that JavaScript will fix everything if you use it. I don't even believe that ;) I am talking about the concept of a promise object that several JavaScript libraries use (including AngularJS, jQuery, Dojo and WinJS). A promise is a pattern for handling asynchronous operations. The problem is that essentially when you start an asynchronous operation, you need to execute some code as the operation is completed.

Asynchronous code is so common that most libraries have found a solution for passing in callbacks. But there is little commonality to how each libraries does this. In this example you can see the jQuery uses the success property of the settings object to specify the callback. The promise pattern sets out to simplify this process. What is interesting here, is that the object that ajax returns is the xhr object which implements the promise pattern so we can call then as seen here.

Let's see how using a promise looks. Create a new fiddle - JSFiddle. Msfrisbie/egghead-angularjs. Let's Get CRUDdy: AngularJS and Node.js Ferrari Example. Jmcunningham/AngularJS-Learning. $resource strips port from url · Issue #1243 · angular/angular.js.

Yeoman - Modern workflows for modern webapps.