Latest Angular.js Recipes

Adding ng-click event with jQuery

Being new to Angularjs, I need a bit of help with this issue. I am attempting to add ng-click="getGallery(57)" to a modal tab. Adding via jQuery is not the issue, however I realize when I do this, Angular is not compiling the newly added ng-click. I...

Read the entire recipe Recipe added 4 minutes ago

Angularjs watch for change in parent scope

I'm writing a directive and I need to watch the parent scope for a change. Not sure if I'm doing this the preferred way, but its not working with the following code:

  scope.$watch(scope.$parent.data.overlaytype,function() {
    console.log("Change...

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

Implementing loading spinner using httpInterceptor and AngularJS 1.1.5

I've found an example of a loading spinner for http/resource calls here on SO:

As you can see the implementation works (using AngularJS 1.0.5)....

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

AngularJS ng-class, condition when form is dirty

In my main html (lets say it uses ng-controller="controller1"), I'd like to put a conditional class on a div that would change its background color whenever a form under ng-controller="controller2" is dirty.

Is there a way to just put that as a...

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

Handling Page Refresh with AngularJS Service and Views

I have a simple SPA with two views: a list view and a detail view. I use a service called StateService to pass data between the two controllers.

I am trying to handle the case where the user refreshes the browser page--when this happens, the...

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

Can anyone provide an example of an angularjs set-up that polls for data and updates the UI when data is received?

Struggling for a good example of this.

I'm want to have a chart directive that will be updated every minute by polling a web service.

I currently have a service which is a wrapper for my web service. My controller can access this service and...

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

How to inject service depending on directive attribute in angular?

I have the following directive

directiveModule.directive('typeahead', function() {
    return {
        restrict: 'E',
        transclude: true,
        scope: 'isolate',
        templateUrl: 'assets/partials/common/typeahead.html' ,
       ...

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

AngularJS: Setting a variable in a ng-repeat generated scope

How do I access the set of scopes generated by an ng-repeat?

I suppose at the heart of this is the fact that I don't understand quite how the relationship works between a) the collection of objects that I pass into the ng-repeat directive and b)...

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

Nesting Custom Directive with ng-repeat

i'm a newcomer with AngularJS,

i'm trying to create a custom directive that applies jQuery JScrollPane (JScrollpane.kelvinluck.com) to a div.

i have the following html code:

<scrollPane> ------> WRONG
<div scroll-pane> -----> RIGHT
    <ul>
      ...

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

AngularJS push item to first or 0 index of $scope array

Please help me implement this function. I have an array of items in my $scope. Now, when I click on the Add Item button, I want to push a new item to the first index or 0 index of that array. Thanks in advance. :)

Here's a working jsFiddle to start...

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

AngularJS - Render HTML tags that are contained in a string

My database stores product information, and a lot of this is organised into lists. I load the data into Angular as $scope.post.

For instance,

$scope.post.size_description = '<li> Fits true to size. Take your normal size\r</li>
   <li> Slim-cut,...

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

How do I mock the result in a $http.get promise when testing my AngularJS controller?

After much reading, it seems that the recommended way to call a web service from an AngularJS controller is to use a factory and return a promise from that.

Here I have a simple factory which calls a sample API.

myApp.factory('MyFactory',...

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

AngularJS Routing Case Sensitivity

I haven't been able to find a straightforward answer to this, which leads me to believe that it's something really really simple. Either way, here I go.

All of the calls in my $routeProvider work great, but are case sensitive. Here's a code...

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

How to Parse JSON response into ng-repeat correctly in Angularjs

I want to be able to use ng-repeat in order to parse my response on the front end. I am having trouble parsing responses that have multiple items versus a single item using ng-repeat list.

I am able to parse; but I have to create 2 different list...

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

Disabling ngClick event handling in a custom directive

Here is a directive in which I'm attempting to disable a link based on a model value:

app.directive('disableable', function($parse){
    return {
        restrict: 'C',
        require: '?ngClick',
        link: function (scope, elem, attrs, ngClick)...

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

angularjs controller executes 2 times

I have a problem where a controller executes twice, yet I do not have duplicates that i can see (even running a case sensiTIve search through my files only shows one in route configuration and my actual controller).

Route...

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

Angular: How to get content from a custom div

I want to get a the content from a custom div tag, I tried various ways to do it, not working well. Here is an example. The general item is to retrieve the content in the custom directive tags. and then bind them into the template. I hope some one...

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

Trigger form validation on ng-click

I created a Plunker that displays a simple form with a required email field. The validation works when the user types in the email but is there a way to trigger the validation when clicking on the button. I don't want to disable the button based on...

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

How to make controller function execute only once in AngularJS?

I have a controller that is referenced in some html. And the html changes on some event so the controller function code executes multiple times.
The problem is that I have a peace of code that needs to be executed only once.
Here is the controller: ...

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

I am trying to bind a text area to an angularjs variable and have it reflect changes I make to the text area with jquery, in the angular js variable

I want to bind a text box to an angularjs variable and have it output rendered html in a separate div. I also want to manage the data in that div with jquery. When I update using jquery the bound angularjs does not update.

I have:

$('#sections,...

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

Angular empty form and remove invalid state from inputs

I'm using a form to add elements to list that is displayed on the side of the form. Markup is:

  <form name="thingForm">
      <input required type="text" ng-model="thing.name"/>
      <input required type="text" ng-model="thing.value"/>
     ...

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

AngularJS - Form data

My dataset is returning a list of employees. I'm attempting to use the fields from the first index to build my form for adding new employees. I'm struggling with reading the form field data to add a new employee. Fiddle is here: ...

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

AngularJS how to add data-image attribute to option

I want to add custom data attribute to option tag.

For example:

<select>
    <option data-image="url 1">Val 1</option>
    <option data-image="url 2">Val 2</option>
    <option data-image=" ... "> ... </option>
    <option data-image="url N">Val...

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

How can I install angular version 1.1.5 via npm

I've tried:

npm install angular@1.1.5

But it give me an error:

npm ERR! Error: version not found: 1.1.5 : angular/1.1.5

How can I install it?

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

How to properly implement angularFireAuth?

I have changed the official AngularJS documentation to use Firebase (the phone tutorial).

This is the router of my app:

angular.module('phonecat', ['firebase']).
 config(['$routeProvider', function($routeProvider) {
 $routeProvider.
     ...

Read the entire recipe Recipe added 1 day ago