Latest Angular.js Recipes

AngularJS $http, CORS and http authentication

Because using CORS and http authentication with AngularJS can be tricky I edited the question to share one learned lesson. First I want to thank igorzg. His answer helped me a lot. The scenario is the following: You want to send POST request to a...

Read the entire recipe Recipe added 27 minutes ago

AngularJS access parent scope from child controller

I've set up my controllers using data-ng-controller="xyzController as vm"

I have a scenario with parent / child nested controllers. I have no problem accessing parent properties in the nested html by using $, but I cannot figure out...

Read the entire recipe Recipe added 1 hour, 27 minutes ago

AngularJS ng-repeat default value does not work

I am working with AngularJS and I am so new in that.

My aim is fill a tag SELECT with OPTION element from a datasource. That is what I do basically:


    function LocalizationController($scope, $http) {
        $scope.Regions = [

Read the entire recipe Recipe added 2 hours, 30 minutes ago

how to get href by ng-click a &lt;a&gt; in angular?

let us say we have a

   <a href = "/jsondata" ng-click="myFunction()">Click Here</a>

in the angular based application.

$scope.myFunction= function(){
        // how to get the href
        $http.get(href).success(function(data) {

Read the entire recipe Recipe added 3 hours, 26 minutes ago

Angularjs sharing methods between controllers

I was reading this article on Angular validation and thought it would be good to use in my own project. It's working really well and I'd like to extend it accessing methods in other controllers upon successful validation of the form. I've tried...

Read the entire recipe Recipe added 4 hours, 31 minutes ago

AngularJs&#39;s templateUrl : Url or ID?

AngularJS docs provide a templateUrl example :

using :

 <div ng-controller="Ctrl">
      <div my-customer></div>

And in the controller :

....directive('myCustomer', function() {
    return {

Read the entire recipe Recipe added 5 hours, 31 minutes ago

Find route from angularjs routeprovider by name

I'm defining my routes like this.

.when('/Home', {
     name: 'Main',
     templateUrl: 'Main.html',
     controller: 'MainController',
     controllerAs: 'ctrl'
.when('/About', {
     name: 'About',
     templateUrl: 'About.html',

Read the entire recipe Recipe added 6 hours, 26 minutes ago

Where do I put event listener code in AngularJS that all controller use?

I want to have some event listener code in my AngularJS app which will apply to the scope of all controllers.

I basically want to define the following somewhere:

    document.addEventListener("online", onOnline, false);

Read the entire recipe Recipe added 7 hours, 32 minutes ago

Passing literal attribute values to angular js directive

I'm having a bit of trouble understanding how attribute values work in AngularJS directives. No matter what I try, literal attribute values come out as undefined when I try to use them within the directive controller.

Say in my HTML I envoke a...

Read the entire recipe Recipe added 8 hours, 33 minutes ago

$setValidity on a field doesn&#39;t invalidate the form

I have a simple form with one field (but with all the ng stuff, it's becoming quite complicated).

<form class="smart-form" name="newAdminForm" ng-submit="addAdminUser()" novalidate="novalidate">

Read the entire recipe Recipe added 9 hours, 29 minutes ago

How do I properly ng-repeat through nested key value pairs in angularJS

View live code:

Angular JS

How in the world do I properly loop through nested key value pairs and properly output them like below?

View I want is a tree like so


Currently the view...

Read the entire recipe Recipe added 10 hours, 31 minutes ago

AngularJS change URL in module.config

I use Restangular in my angularjs App & use setErrorInterceptor to handle response error in one place. I want to redirect user to login page if an error occured. I know that the only providers & constants are injectable in configuration phase.


Read the entire recipe Recipe added 11 hours, 33 minutes ago

Wrapping controller in anonymous function

whether i do:

(function () {
'use strict';

// Create the module and define its dependencies.
var app = angular.module('app', [
    // Angular modules 
    'ngAnimate',        // animations
    'ngRoute'           // routing

    // Custom...

Read the entire recipe Recipe added 12 hours, 30 minutes ago

Angularjs - dynamically attach attribute value to bound object. How?

I tried searching for this but I didn't quite know how to phrase the idea.. Let me try and explain. I am still trying to grasp the whole scope in directives thingy..

The code below are some variations of the same directive (it is not a lot of code,,...

Read the entire recipe Recipe added 13 hours, 30 minutes ago

(Angularjs) How to $http.get data and store it in service

As you will see i'm new in AngularJS, JS and in web development at all =) really sorry for that but i try to.

I try to build a massive webform (about 200 different fields) with AngularJS controllers. I need access from controller to root data source....

Read the entire recipe Recipe added 14 hours, 32 minutes ago

Angular forms: setting a $dirty property on a custom directive

We have a directive (let say check-button) that creates a styled checkbox with some specific functionality.

I require ng-form in the directive, So I can user the formCtrl in the directive and I succeed in setting the form to be $dirty or $valid. My...

Read the entire recipe Recipe added 15 hours, 31 minutes ago

AngularJS e2e Testing with Protractor

I am attemping to get the last row of a ng-repeat(ed) table via protractor to test and ensure the object I just created in a previous test run shows up. I have gotten as far as getting all of the text of the row but cannot seem to figure out through...

Read the entire recipe Recipe added 16 hours, 32 minutes ago

is there a shortcut to get window.history.back()

AFAIK, the only way to get Angular mimick a back button behavior is via a call to $window.history.back.

Now, I have a form with two buttons: submit and cancel. When I submit, I have some custom logic, and in the end I can easily call the back()...

Read the entire recipe Recipe added 17 hours, 30 minutes ago

Is it an antipattern to use angular&#39;s $watch in a controller?

In my never ending quest to do things the "proper" angular way, I have been reading a lot about how to have controllers observe the changes in models held in angular services.

Some sites say using a $watch on a controller is categorically wrong:


Read the entire recipe Recipe added 18 hours, 33 minutes ago

Uncaught ReferenceError: angular is not defined - AngularJS not working

I'm attempting to learn angular and I am struggling with a simple button click. I followed an example which has identical code as below. The result I am looking for is for the button click to cause an alert. However there is no response to the button...

Read the entire recipe Recipe added 19 hours, 30 minutes ago

angular: toggle text of button based on boolean value in model

what is a simple way to change the text in a button element based on boolean value?

pseudo code:

<button> some text OR some other text    </button>

I read this: Angularjs if-then-else construction in expression

and this regarding ng-switch: ...

Read the entire recipe Recipe added 20 hours, 31 minutes ago

Using bootstrap collapse with angularjs

I'm trying to include the below bootstrap collapsible panel in my angular application. However, when I click on "Expand", angular seems to see href="#collapseOne" and then redirects to the home page instead of collapsing the panel. My routing looks...

Read the entire recipe Recipe added 21 hours, 30 minutes ago

Restrict input as numbers on input fields using AngularJS

I am trying to restrict input as numbers on below fields

Postal Code:
<input type="text" id="zipCode1" name="zipCode1" size="4" maxlength="5" ng-model="zipCode1" ng-change="myNumbers(zipCode1)" />
<input type="text" id="zipCode2" name="zipCode2"...

Read the entire recipe Recipe added 22 hours, 33 minutes ago

how to check if an element is enabled

I need to check with Protractor if a button in my angular application is enabled, for so this is my test:

    it('submit should not be enabled',function() {
      var price ='price'),
          oldCategory ='oldCategory'),

Read the entire recipe Recipe added 23 hours, 25 minutes ago

Is it really worth mixing AngularJS and or KendoUI?

Recently, in working with AngularJS, I really like many of the features, like creating custom abstract data factories, etc.

KendoUI also has similar features like MVVM, SPA routes, etc. that AngularJS offers, so I'm curious about what the benefits...

Read the entire recipe Recipe added 1 day ago