How to get evaluated attributes inside a custom directive

Notice: I do update this answer as I find better solutions. I also keep the old answers for future reference as long as they remain related. Latest and best answer comes first. Better answer: Directives in angularjs are very powerful, but it takes time to comprehend which processes lie behind them. While creating directives, angularjs … Read more

SPA best practices for authentication and session management

This question has been addressed, in a slightly different form, at length, here: RESTful Authentication But this addresses it from the server-side. Let’s look at this from the client-side. Before we do that, though, there’s an important prelude: Javascript Crypto is Hopeless Matasano’s article on this is famous, but the lessons contained therein are pretty … Read more

Share data between AngularJS controllers

A simple solution is to have your factory return an object and let your controllers work with a reference to the same object: JS: // declare the app with no dependencies var myApp = angular.module(‘myApp’, []); // Create the factory that share the Fact myApp.factory(‘Fact’, function(){ return { Field: ” }; }); // Two controllers … Read more

Submit form on pressing Enter with AngularJS

Angular supports this out of the box. Have you tried ngSubmit on your form element? <form ng-submit=”myFunc()” ng-controller=”mycontroller”> <input type=”text” ng-model=”name” /> <br /> <input type=”text” ng-model=”email” /> </form> EDIT: Per the comment regarding the submit button, see Submitting a form by pressing enter without a submit button which gives the solution of: <input type=”submit” … Read more

What’s the difference between returning value or Promise.resolve from then()

In simple terms, inside a then handler function: A) When x is a value (number, string, etc): return x is equivalent to return Promise.resolve(x) throw x is equivalent to return Promise.reject(x) B) When x is a Promise that is already settled (not pending anymore): return x is equivalent to return Promise.resolve(x), if the Promise was … Read more

How to pass parameters using ui-sref in ui-router to the controller

I’ve created an example to show how to. Updated state definition would be: $stateProvider .state(‘home’, { url: ‘/:foo?bar’, views: { ”: { templateUrl: ‘tpl.home.html’, controller: ‘MainRootCtrl’ }, … } And this would be the controller: .controller(‘MainRootCtrl’, function($scope, $state, $stateParams) { //.. var foo = $stateParams.foo; //getting fooVal var bar = $stateParams.bar; //getting barVal //.. $scope.state … Read more

AngularJS : Difference between the $observe and $watch methods

$observe() is a method on the Attributes object, and as such, it can only be used to observe/watch the value change of a DOM attribute. It is only used/called inside directives. Use $observe when you need to observe/watch a DOM attribute that contains interpolation (i.e., {{}}’s). E.g., attr1=”Name: {{name}}”, then in a directive: attrs.$observe(‘attr1’, …). … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)