Latest Angular.js Recipes

$on event callback parameters

In my .run function I have something like:

$rootScope.$on("$routeChangeSuccess", function(event, args){...})

(Angular ver 1.2.10)

[edit] Where in the documentation can I find out what is passed for args for the event $routeChangeSuccess?

Read the entire recipe Recipe added 41 minutes ago

Refresh scope on every x time using $timeout

I am a newbie to angular. I want to use $timeout of angular to refresh scope after few minutes. I am working on an social app where i need to refresh notification scope after few minutes. Getting notification from a http request using...

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

ReferenceError: <module> is not defined when running Jasmine unit tests in Karma

I am getting a failed test with the error ReferenceError: dmeApp is not defined. Do I need to inject dmeApp into the test? I'm following a tutorial I found here: http://andyshora.com/unit-testing-best-practices-angularjs.html

app.js:

...

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

Can't open Angular app using file protocol in Chrome

Hi i have a problem with angularjs and chrome, this is the code:

   var angularRoutingApp = angular.module('angularRoutingApp', ['ngRoute'])

   // Configuración de las rutas
   .config(function($routeProvider) 
   {

 $routeProvider
    .when('/',...

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

Implementing angularjs directives as classes in Typescript

So after taking a look at some of the examples of angularjs directives in typescript, it seems most people agree to use functions instead of classes when implementing them.

I would prefer to have them as a class and attempted to implement them as...

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

Angualrjs ng-src async image loading from a function call

I am wondering if it's possible to assign a result of a function call to an ng-src in an image?

Basically, I need to retrieve a set of thumbnails for a set of data from an aspx page, there may or may not be a thumbnail. So I need to show a different...

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

Adding dynamic colors in ng-repeat

Just trying to get a handle on angularJS as was building a simple little app where you can make a list of people and in the list their names are colored. The color is chosen by a select drop-down box.

The trouble is any way I try to add the new color...

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

Angular resource custom URL is using query strings and POST parameters

I've written a custom method on an Angular resource in my application for activating a user. The API endpoint is /users/activate and an activation code must be PUTed to this endpoint. This is what my resource looks like:

app.factory('User',...

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

AngularJS - ng-model fails on <span>

I'm learning AngularJS. I've come across something I can't explain, nor can I find any explanation for (or solution).

I have a simple AngularJS app and I am attempting to bind a <span contenteditable="true"> to a value, but it doesn't work. ...

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

Dependency errors in Angular when creating an $http interceptor as a standalone module

Here is a working example of how I have set up an interceptor which attaches an authentication token to each request (this is more or less the example from https://docs.angularjs.org/api/ng/service/$http)

angular.module("app", [])
.config(function...

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

Make angularjs $resource return array of [OO] objects

How to make angularjs $resource return an array of objects derived/prototyped from specified domain object?

Here is an example on http://plnkr.co/edit/AVLQItPIfoLwsgDzoBdK?p=preview that processes a set of Notes objects.

app.controller('MainCtrl',...

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

AngularJS : controller scope won&#39;t sync with promise

I've picked up a project and I'm trying to return some data from a service to my controller. I've been at this for about 12 hours, and have tried different methods. They all usually result in this same kind of 'missing data'.

I've tried

  • using...

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

Angular way to open and close panels

In Angular if I had a few panels, similar to tabs how do you open the panel on click and animate it up, if I click a different panel new html is loaded in, but if I click an open panel it needs to animate down.

Almost exactly like ...

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

Show a div based on if a date is less than 14 days away

I want to show a div of form fields in a form (containing reason for rush service) if the value of Due_Date is a date less than or equal to when the form is completed.

I have tried ng-if but it waits until the form is submitted to work and I tried to...

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

navigation from one page to another in angularjs

I know i have already asked the same question but i am getting nowhere with this problem..I am trying to navigate from login page to next page...

login.html

<body>
<div id='content' ng-app='myApp' ng-controller='LoginController'>
<div...

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

How to embed SVG image icon in input tag?

I'm trying to embed 'search.svg' image into textbox in AngularJS as shown in the image below enter image description here

But I didn't get expected result. It's rendering like shown in the image below enter image description here

I have tried - My html file

<div class="right-inner-addon pull-left...

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

Angular UI Modal 2 Way Binding Not Working

I am adding an Angular UI Modal where I am passing the scope through to the Modal Window for 2 way binding. I used the resolve method to pass the scope value. Doing so works sort of works meaning when the ng-model value changes in parent, it reflects...

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

ng-class on selected element Angularjs

I have a situation where i am sorting data on the basis of expression:

html :

 <ul>
  <li ng-click="expression = 'created_at'" ng-class="latest_icon: 'selected'" >latest post</li>
  <li ng-click="expression = 'popularity'" ng-class="popular_post:...

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

Facebook comment plugin Angularjs

I am facing a strange error while adding the facebook comment plugin in my AngularJS app. The simplified structure of the app page is

<html ng-app="myapp">
<head>
 ...
</head>
<body>
<div>
...
</div>
<div ng-view></div>
...
</body>
</html>

The...

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

Angularjs $state open link in new tab

I'm trying to implement an "open link in new tab" function using $state.go function. It would be awesome if there was smth like:

$state.go('routeHere', {
    parameter1 : "parameter"
    }, {
    reload : true,
    newtab : true // or smth like...

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

Angular.js promise not resolving when unit testing service with karma

I am trying to unit test an Angular.js service, and need to set an expect on a promise returned from a Mock service (using Jasmine). I am using the karma unit testing framework. The relevant code snippet is below:

// I can't figure out how to do the...

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

ui-router dynamic template path

I'm using ui-router 0.2.8. I'm wanting to load a template based on device width. I can get the device width without issue, set it in the scope etc but I can figure out how to bind it to $stateParams. I have the scope variable in another controller...

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

Image with src inside ng-repeat

I have a template like this

<div ng-repeat="product in products">
    <img src="{{product.Link}}" />
    .....
</div>

Each time this is regenerated it results in the browser clearing out the img and placing it back in again and will therefore...

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

How do I bind to a custom event in an angularjs directive?

I am having trouble catching an event which is sent like this:

document.body.dispatchEvent(event);

The directive below is on a div, inside the body:

.directive('myDirective',function(){
  return {
    restrict: 'A',
    link: function(scope,...

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

angularjs tab key press prevent default

Hi I have a input field that calls the funciton add_plu() when the tab key is pressed down. Although it works, it moves to the next element of the page (default action for a tab key).

How do I prevent the tab button from it's default behaviour? ...

Read the entire recipe Recipe added 1 day ago