Latest Angular.js Recipes

AngularJS how to handle a Bootstrap datepicker date to send it out for a REST backend

I have a angular-strap bootstrap datepicker

<input id="dp5" class="span8" type="text" ng-model="obj.date" data-date-format="mm/dd/yyyy"  placeholder="Pick a Date" bs-datepicker>

The backend is a Spring MVC REST application which originally returns...

Read the entire recipe Recipe added 46 minutes ago

How to format date in AngularJS when posting data to a REST end point

I have a Spring MVC REST backend application. I'm sending the date in "mm/dd/yyyy" format to the client.

But if I format the date in "mm/dd/yyyy" and POST it back, data binding fails.

Here is my Spring customdateserializer obj that converts...

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

How can I add some small utility functions to my AngularJS application?

I would like to add some utility functions to my AngularJS application. For example:

$scope.isNotString = function (str) {
    return (typeof str !== "string");
}

Is the best way to do this to add them as a service? From what I have read I can do...

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

AngularJS template variables not rendering when inside custom directive

I'm having an issue with a custom angular directive. Basically, in the example below, the variable "name" will render correctly if outside of the scope of the directive, but not when inside the directive.

Template:

<div...

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

How to make Angularjs route work with expressJs route on html5mode

i have posted a question on stackoverflow (css and javascript didn't include on refresh) yesterday asking the question about why the css and javascript didn't include on my webpage after I refresh the webpage and found out it caused by the html5mode,...

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

What advantage is there in using the $timeout in Angular JS instead of window.setTimeout?

I had a suggestion to implement a timeout like this:

  $timeout(function() {

    // Loadind done here - Show message for 3 more seconds.
    $timeout(function() {
      $scope.showMessage = false;
    }, 3000);

  }, 2000);
};

Can someone tell me...

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

angularjs angular doesn&#39;t read the length of an array


for the passed few days I am struggling with the matter of AngularJS. I am novice at this and that's where my troubles result from.
Anyway here is my problem. I have an app that is made made for asking users some questions, collecting answers and...

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

function called twice inside angularjs controller

I am new to angular js and currently stuck with very wired kind of a bug. function in a controllers runs twice when its called by view loaded against a route.

http://jsfiddle.net/4gwG3/5/

you will see alert twice!!

my view is simple
...

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

Translate Angular-UI pagination

How can I translate text in Bootstrap UI pagination directive?

I've overrided the constants like this for french translation:

angular.module('myapp', ['ui.bootstrap'])
    .constant('paginationConfig', {
        itemsPerPage: 10,
       ...

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

How can I fade in and then fade out text inside a &lt;div&gt;

My Web page has the following tag:

<div data-ng-model="modal.data.message"></div>

Is there a simple way using that I can make a message "autosaving" fade into view in the <div> and then fade out a couple of seconds after the function...

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

how to change the headers for angularjs $http.jsonp

I read the document.

but I think I must have misunderstood it.

$http.defaults.headers.jsonp = { 'Accept' : 'application/json'};
$http.jsonp(url).success(function(data, status, headers, config) {

I also have...

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

How to handle document click and notify other controllers using AngularJS?

I have created a horizontal drop down menu using AngularJS.

The menu section is managed by an angular controller called menuController. Standard menu behavior is implemented, so that on hover main menu item gets highlighted unless it is disabled. On...

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

console.log in AngularJS executing after scope function

I am new to Angular JS and I have a basic Angular App that simply sets up a scope object, sets up a few functions to initialize/create the scope object. When I use a console.log within my function it is reporting the $scope values that are set at the...

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

Using ng-repeat and limitTo to limit the number of visible items displayed

I'm trying to limit my result sets to a fixed number. I can use limitTo with ng-repeat, but this limits items regardless of their current visibility and removes items from the DOM. I want to limit to a number of visible items while keeping everything...

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

How to select option in drop down protractorjs e2e tests

I am trying to select an option from a drop down for the angular e2e tests using protractor.

Here is the code snippet of the select option:

<select id="locregion" class="create_select ng-pristine ng-invalid ng-invalid-required" required=""...

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

In Angular, is there a way to prevent flicker in expressions that contain concatenated values?

Is there a way to prevent flicker for templates that contain concatenated values such as {{person.LastName+ ", " + person.FirstName}}?

I don't want to see the "," until $scope.person is bound.

Is this something that I might put into a filter? Would...

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

angularjs ng-disabled doesn&#39;t add disabled to button

I have an input button that I want to set to disabled if a user selects a certain value from a select box:

Select menu:

<select id="jobstatus" name="jobstatus"  ng-model="associate.JobStatus" class="form-control">
        <option...

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

How to use bindonce directive in ng-grid?

I am having a serious performance issue in my application. I am using angular and ng-grid. After some reading for why my app is slow, I was directed to use bindonce directive to overcome potential Angular performance issues.

So I added bindonce.js in...

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

In Angular, what&#39;s the conceptual difference between the error and catch functions for promises?

I finally got Angular promise error handling down but it was counter-intuitive to me. I expected errors to be handled by the failure callback but instead I had to use a catch.

I don't quite understand conceptually why the catch is executed rather...

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

AngularJS service retry when promise is rejected

I'm getting data from an async service inside my controller like this:

myApp.controller('myController', ['$scope', 'AsyncService',
function($scope, AsyncService) {
    $scope.getData = function(query) {
        return...

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

AngularJS app not running correctly

I'm new to AngularJS. I'm trying to run a simple example from a book, but it's not working correctly, and I can't figure out why.

This code runs fine:

<html ng-app>
<head>
    <script src="angular.js"></script>
    <meta charset="UTF-8">
   ...

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

Get specific JSON object by id from JSON array in AngularJS

I have a JSON file containing some data I d like to access on my AngularJS website. Now what I want is to get only one object from the array. So I d like for example Item with id 1.

The data looks like this:

{ "results": [
    {
        "id": 1,
   ...

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

ng-repeat and ng-controller on the same DOM element

Can we attach ng-controller and ng-repeat to the same DOM element? Fiddle

Here is the HTML:

<table>
    <tbody ng-controller="UserController" ng-repeat="user in users" ng-click="toggleSelectedUser()" ng-switch on="isSelectedUser()">
        <tr>
  ...

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

Saving a checkbox list in Angularjs with node

I want to save and load a checkbox list using binding in angularjs with a node backend. This SO question (How do I bind to list of checkbox values with AngularJS?) answers how I can load the check box from a static javascript object but how can I save...

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

TypeError: &#39;undefined&#39; is not a function (evaluating &#39;mockBackend.expectPost(

I am trying to unit test an angularjs controller with Karma, and jasmine.

Here is my test suite:

describe('Controllers', function(){
    var $scope, ctrl;
    beforeEach(module('curriculumModule'));
    describe('CreateCurriculumCtrl', function(){
 ...

Read the entire recipe Recipe added 1 day ago