Latest Angular.js Recipes

angularjs unit test karma with jasmine mock dilemma

I am currently writing tests for some services using karma with jasmine, and I was wondering if I had to mock a service's service dependency that uses $http, as described below.

PS: I'm already using $httpBackend to mock any GET request, and I plan...

Read the entire recipe Recipe added 43 minutes ago

Wait for all promises to resolve

So I have a situation where I have multiple promise chains of an unknown length. I want some action to run when all the CHAINS have been processed. Is that even possible? Here is an example:

app.controller('MainCtrl', function($scope, $q, $timeout)...

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

AngularJS test, can't find my controller

I met a problem with testing my controllers. I load them dynamically (lazy load, see after) so I wrote them like this :

angular.module('myApp').controllerProvider.register('DashboardCtrl', [
    '$scope', function ($scope) {
        $ =...

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

AngularJs dynamic form generation with validation

I am trying to generate form dynamically and use validation at the same time. The problem that I have now is that the input attribute name='{{key}}' is not interpolated by the validation.

<div ng-repeat="options in formObject">

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

No spacing between bootstrap-labels with ng-repeat

When I am adding labels using ng-repeat from angular.js, they are shown without spacing. Here is a Plunker which demonstrates it.

But if I add labels manually, just has copied html, then they are shown with whitespace.

Is there a way to add white...

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

Binding external URL in angularjs template

I have a angularjs app with a controller and a partial wired up..

In my controller I have a array of links..

$scope.links = ['',''];

In my partial, I have the following code..

 <div ng-repeat="link...

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

Angular http request with json param

In my RESTful api one of the resources exposes a GET method that accept json as a parameter named 'query'. This parameter is passed directly to the MongoDB query allowing users to query the database directly using mongo syntax.

The problem I'm having...

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

Angularjs and Jasmine: Testing a controller with a service making ajax call

I am very new to testing javascript. My application is using angularjs. I am using jasmine as a testing framework.

Here is the controller I am testing:

angular.module('logonController', ["ngval", "accountFactory"])

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

how to send the input text box value to angularjs onclick on the text box

Below is my html:

<tr ng-repeat="c in client">
     <td><input type =text id = "id" value = {{}} onclick = "display();" > </input> </td>
     <td><input type =text value = {{c.fname}}></td>

My js:

 function display()

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

Using ng-if inside ng-repeat?

i am working on Angular app. I tried to use ng-if and switch inside ng-repeat but didn't succeed. I have data like:


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

Angular js - $anchorScroll smooth/duration

Hi reading the Angular Js doc i have no idea if $anchorScroll can have a duration/easing option to smooth scroll to elements.

it only says:


    // call $anchorScroll()

Since i do not use jquery and...

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

how to show/hide a div on the basis of a checkbox selection in angular js

I have a checkbox and a div on my page.

<input type="checkbox" id="Animals" name="Animals" ng-model="ModelData.Animals" 
                            ng-checked="ModelData.Animals == 'A'" />

 <div class="form-group" ng-show="ModelData.Animals ==...

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

AngularJS ng-table cannot set property &#39;$data&#39; of null

I've just started using ng-table and I'm trying to test it through jasmine unit tests (not sure if this is the best way to test my controllers) and I keep running into this error;

TypeError: Cannot set property '$data' of null

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

Best way for deploy angular.js application made with yeoman?

I´m building application SPA using angular.js with yeoman which connect with a API RESTful made in Java using spring-MVC . i´m begginer for deploy web applications in angular and so i want to know some differents alternatives or best practice ,...

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

AngularJS disable directive

I am using the editable-text directive from the xeditable module for AngularJS. Is there a way to disable the directive for the entire page?

I thought about using replacing editable-text with {{variable}}, where variable="editable-text" to enable and...

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

How to access and use index of each item inside ng-repeat

I have a table where the last column in each row contains a little loading icon which I would like to display when a button inside the table is clicked.

When each table row is generated with ng-repeat, the loader shows up in every row rather than...

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

Use Angular to copy object properties - without values - to another object

We have tried angular.copy and angular.extend. Both of these, though, copy property values. How do we copy one object's properties, without their values, to another object?

Here is a fiddle with our attempts based on ...

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

Lazy Loading of Angular Component Scripts when Changing States

This problem has been taking up the last day or so.

I've been trying to get my AngularJS application to load the script files for each state's components lazily. I'm working on a large project at work in Angular, and the index.html file has morphed...

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

AngularJS and quirks mode: blank screen on IE8+

I'm working on an Angular project that will be included in a HTML page I don't have control on. Actually I only have access to what is inside the <body> element.

There are many constraints which are not the easiest to deal with: 1- I can't change...

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

Add JSON Object to angularjs $scope?

How do I inject my JSON Object in my angular $scope upon create()?


<input type="text" class="title" placeholder="hold" ng-model="formData.text"/>
<input type="text" class="desc" placeholder="description" ng-model="formData.desc"/>


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

Call callback function on esc in Angular UI Bootstrap&#39;s modal

I'm using a modal of Angular UI Bootstrap that can be closed via a Cancel button or via ESC. As I have to do some cleaning when it closes, I've written the 'cancel' method in the scope, but this is only called when clicking this Cancel button, how...

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

properties from resolve object not passing to controller, unknown provider error

Before voting this down, yes this question has been asked here already, and answered, but the answers are not satisfactory. They all correctly suggest to add the controller in the route configuration, but this is not the case here.

The expected...

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

Angularjs - $rootScope in directive link function

I am asking this question because I am not quite clear on how to think of rootscope as a dependency passed to directives

I have a directive that needs to display some information from $rootScope ...

I thought I needed to pass the $rootScope to a...

Read the entire recipe Recipe added 2 weeks, 3 days ago

AngularJS filter on multiple values of one field

I need to be able to filter on two different values of one field of an object. Take the following example.

$scope.products = [

Read the entire recipe Recipe added 2 weeks, 3 days ago

AngularJS 1.2 storing data arrays in services

I have a question, seeking advice, on how to get data that is stored in service arrays to the controller since unwrapping promises was removed in 1.2.


  1. Route one contains a list of items
  2. Route two contains a form to add a new item
  3. Once the...

Read the entire recipe Recipe added 2 weeks, 3 days ago