Latest Angular.js Recipes

Is there a way to watch attribute changes triggered from outside the angular world?

I’m trying to understand interactions between the angular world and the non-angular world.

Given a directive that one declares like this:

<dir1 id="d1" attr1="100"/>

If code outside angular changes the directive this way:


Read the entire recipe Recipe added 46 minutes ago

How do I pass promises as directive attributes in Angular

I'd like to set up a promise and then throw it into a directive (using the databinding '=' attribute type) and do the then magic within the directive, but passing the promise as an attribute seems to result in the promise being resolved as undefined,...

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

AngularJS - ng-option dropdown list not setting ng-model value when False selected

I have a <select> element that uses ng-optiona to generate the select list and hopefully set the selected to the value of the ng-model. Here is my html:

<td style="text-align:center">
    <ng-form name="IsTobaccoForm">
        <select name="Input"...

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

How do I dynamically load a template based on parameters in a route registered with $routeProvider?

I found that you can use template or templateUrl as a function like that

     return: '/'+params.controller+'/'+params.action

And then I wondered if it's possible lazy load the...

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

AngularJS $scope.$watch properties of $ but send old values to server before change

I have an object $ in my controller. I want to watch for any changes in $ and $ and do a get request and replace all the data in $ object. Before this change happens, I would like to send the data of...

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

angularjs custom confirm box

So I'm trying to implement a custom confirm box using Angular. Ideally, I would simply like to add an attribute to enable the functionality. Example:

<button type="button" ng-click="delete(foo)">Delete</button>  ->  <button type="button"...

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

Angular expression if array contains

I'm trying to add a class to an element if a jobSet has not been selected for approval using expressions.

<li class="approvalUnit" ng-repeat="jobSet in dashboard.currentWork" ng-class="{-1:'approved'}[selectedForApproval.indexOf(jobSet)]">


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

Using Angular to Download a File via Ajax

I have a service that generates a CSV file and returns it to the page via an http/ajax get. I'd like a user to click a button, have the service get called, and then have the file get downloaded to the user's browser.

I would like to do this The...

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

Angularjs loading screen on ajax request

Using Angularjs , I need to show a loading screen (a simple spinner) until ajax request is complete. Please suggest any idea with a code snippet.

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

Populate AngularJS model with existing values

I'm adding a mild amount of angularjs to my existing application. I'm starting with utilizing controllers to manage my forms which are all submitted by ajax. The forms are currently pulled into the page using jQuery's $.load() function and the form...

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

How to trigger a directive when updating a model in AngularJS?

I found a good solution for inline editing content in angular js that is created by running ng-repeat on a model:

To expand on that solution I added a button to the page that has a ng-click directive as...

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

Two way databinding in Select2 for AngularJS doesn&#39;t work

I am having issues with using the Select2 plugin in AngularJS. I can load the items fine, and retrieve the selected item from my ng-model, but I have issues, that the dropdown isn't updated if I update the ng-model.

In my view the code looks like...

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

Getting Response from Restangular POST

How do I get the response object after I send a Restangular POST?"Buildings", myBuilding).then(function() {
   console.log("Object saved OK");
 }, function() {
  console.log("There was an error saving");

I'm trying to get...

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

Angular Directive throws $digest already in progress when trying to call controller method

Here is my plunker -

  • I want to keep the knowledge of controller method outside of directive so used Directive Attribute and pass controller method inside
  • Now it is failing that $digest already in...

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

Angular - extending $resource subobject with custom methods

In most cases the result of <custom-resource>.query() method is an array, which can be easily extended with some methods (business logics) with the following (factory) code:

var Data = $resource('http://..'); = function() {return...

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

AngularJS: how to change scope in one controller with trigger in the other controller

I have two Controllers and one shared Service. First Controller renders some text. Other Controller has a button that had to change the First Controllers scope and rerender text (with new value)


<div ng-controller="Controller1">
  Value is:...

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

How to use mock $httpBackend to test error branch

I am following the AngularJS documentation from here

The problem is that the documentation describes only the "success/happy" branch of the code, and there is no example of how to test the "failure" branch.

What I want to do, is to set the...

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

Stop $timeout when starting new controller

I'm polling for my data every 2 seconds to keep them updated on the page. My problem is when I visit another page the timeout stays active. How can i cancel my timeout when I visit an new page?

function IndexCtrl($scope, $timeout, RestData) {

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

ng repeat dosn&#39;t update itself after inserting new item using dialog

I am just a beginner with angularJs , and i am trying to do CRUD Operations using $http and MVC :-

  1. I am using ng-repeat to display list of "Terms" .

  2. I have a button to display a dialog ,which in turn will be used to inserting new "Term"....

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

Basic AngularJS google maps

I am fairly new to angular and was trying to take a stab at angular google maps.

My requirements. I have a search bar which is for searching for restaurants. The search results api gives me address, latitude and longitude of the restaurant searched...

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

og meta tags, social buttons and angularjs

I'm creating a website using multiple views. The tag and the tags of the page get changed through a a $rootScope variable. so I have something like

   <title ng-bind="page_title"></title>
   <meta property="og:title"...

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

Testing a AngularJS services with dependencies

I have som issues testing a simple service in AngularJS, which depends on another service.

The service looks a bit like this:

serviceModule.factory('filtersService', ['$rootScope', 'urlService', function($rootScope, urlService){
        return {

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

UPDATE: Responsive images in AngularJS

Original Issue for Posterity (see updates)

I've got an Angular.js website I'm building out to be responsive. I wanted to use separate resolution images for different browser widths as well. So, I stumbled upon Picturefill.js, which seems like it...

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

Using filters inside a ternary operator in AngularJS

Is there a method for applying a filter to a variable in the template when it is part of a ternary operation?

<img ng-src="{{ image_url && image_url|filter:"foo" || other_url }}">

In this case the filter is a custom filter, but one that I don't...

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

destination.push is not a function ngResource save() AngularJS

ngResource save() to a mailer API using $resource can be demonstrated here:

The message sends, however I am getting an error in my console log:

destination.push is not a function

  • What is causing this...

Read the entire recipe Recipe added 1 day ago