Latest Angular.js Recipes

Angular / Ionic - controller only runs once

I'm starting out with Angular through the Ionic Framework but I am failing to understand why the controller only runs once i.e. I change state, the controller runs, change to another state and then back again and the controller does not run a second...

Read the entire recipe Recipe added 24 minutes ago

Disable refresh browser in only one page using angularjs or javascript

I would like to ask if it's possible to disable the refresh of the browser in one page only using angular or javascript.

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

AngularJS $ how to set the json data into request body

I am trying to send the post request with json data to server. But seems angularJS $ method does not set the data into body. How can I make it set the data into body?

The remote server is implemented use webapi and will read the data...

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

Only allow certain number of characters to type in angularjs/ionic

I have this text field and i need to stop the user from typing more than the allowed character. Lets say i want the user to type only 10 characters and if he types more the text field won't take it.It has to stop getting input after the character...

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

Convert object values into array the Angular way

I have the follow object:

 formData : {
       _id: "550de8956e2d0948080e220f" 
       category: "Tag1"
       isFeatured: "Yes" 
       likeCount: 557 
       title: "Integrating WordPress with Your Website"

I tried JavaScript but it...

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

Mixed POST submit from AngularJS to Spring RestController

Basically I want to be able to post a form with some fields (JSON) and an attachment (multipart). Following is actually working code, the problem is that I don't like it so it mainly functions because of workarounds.

Angular controller


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

issue with $watch on factory object

I have a variable socialRegisterFactory.pages set up in my factory that updates once information from FaceBook is fully loaded. I'm trying to $watch this variable in my controller so that when the info is loaded and when that variable changes from...

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

How to get rid of Uncaught SyntaxError: Unexpected token :

I am having a controller like this :

ListNewsCtrl.$inject = ['$http', '$scope', 'datacontext'];
function ListNewsCtrl( $http, $scope, datacontext) {
   $scope.realTimeData = [];
   var url...

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

AngularJS Directive Two-Way Data Binding Not Working When Observing Boolean

I have a two-way data binding that is not altering the value of the variable sent to the directive.

My directive watches for a trigger and gives focus to the associates element (based on code found here at SO):

app.directive('focusMe', function...

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

AngularJS - binding array value to input ngModel

I have $scope.myArray, and it's binding with an input field by ngModel and the expression {{myArray}}

My issue is when I modified myArray by call changeMyArray(), the input's value did not change. But the expression {{myArray}} is display new...

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

Angular Bootstrap - Default tab active (dynamic tab)

I have an issue with Angularjs Bootstrap Tabs. I want a dynamic tab to be active by default but it seems I can't as long as I have a static tab inside the same tabset.

<tabset ng-init=" = true">
    <tab ng-repeat="tab in tabs"...

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

How to add validation attributes to md-autocomplete angular material directive

I'm using version 0.7.1 of angular material. I'm using the autocomplete as described here: Autocomplete demo

However, it doesn't seem to support validation logic, even though it generates a textarea: Autocomplete directive documentation

I imagine...

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

selected option into ng-repeat

I'm having the following script,

 <select ng-model="create.Category" class="form-control input-sm" name="category" required>
   <option value="" disabled="" selected="">Select Category</option>
   <option ng-repeat="cat in categories" value="{{...

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

How to force validation to run on model when other model changes?

I have an input field with a number of $validators registered on it that updates the model. Some of these validators does comparisons to other values on the scope (which are also updated with input fields).

How do I force AngularJS to run these...

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

Why am I getting Error:(45, 1) TS2304: Cannot find name &#39;angular&#39;. in WebStorm

I am just starting out with TypeScript and trying to add it to an existing AngularJS project.

I have 'excluded' the bower directory where angular is installed and downloaded the definitelyTyped definitions for angular in the preferences...

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

How to apply an ng-if (or other conditional) in multiple &lt;td&gt; elements while keeping it DRY

I want to display a number of <td> elements based on the same condition. I am currently doing that with multiple, identical, ng-if directives, as such:

    <td> Display unconditionally </td>
    <td> Same here... (imagine more columns)...

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

Detect Input text length in angularjs

I am beginner in Angularjs

<div ng-app>
  <input type="text" ng-model="Number"/>

I know can use {{Number.length}} to display input field length, But how detect length etc..

if (length == 0) {
  // do something
} else if (length == 1) {

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

Not able to set column width in angular datatables

var app = angular.module('tableTest', ['datatables']);
app.controller('TableCtrl',function ($scope,$compile,DTOptionsBuilder, DTColumnBuilder) {
$scope.showUpdateForm = function(code,reason,startTime,endTime,transactionGroup,geoGroup,transactionGroup)...

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

Ng-Show causing flicker

I have tried the following, but am still getting a flicker when using ng-show: Angularjs - ng-cloak/ng-show elements blink

I am using a template to load my top nav as follows:

<div data-ng-controller="userInfoCtrl">
   <a href="#!home">Home</a>

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

angular ui-grid event: row selected

I am trying to enable/disable a button based on the selection of a row on a ui-grid. If there are no rows selected, the button is disabled.

I found this plunkr with the old ng-grid way of firing an event after a row is selected.


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

Cant convert JSON to array in Angular.js

Hi everyone I have some problems with angular, I made a request in $http so i have a JSON like:


and I want to convert it to an array like

{y:1, a:0}

I'd already tried whit angular.fromJson(myData) but it doesnt works Hope...

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

Hide/show an element in Angularjs using custom directive, ng-show and $scope

When a link is clicked in the app navigation a dropdown with ui-view content shows below each respective link.


   <div class="sc-dash-header">
        <a class="navbar-brand" show-nav-popup href="">download</a>

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

How can I pass a Laravel variable into my AngularJS view?

I am building a small photo application to learn AngularJS 1.3. I come from a PHP background so conceptually this is rather different for me :)

I'd like to pass a variable (the URL of my photos folder) into my AngularJS view (an .html file). How can...

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

Difference between angular.fromJson and $scope.$eval when applied to JSON string

In my angularjs apps, I usually parse a JSON string by using angular.fromJson, like so:

var myObject=angular.fromJSON(jsonString);

However, it seems that I would obtain the same result by using $scope.$eval:


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

AngularJS -- Toggle class for only one element (ng-class and ng-click)

I'm trying to apply a class to only one element at a time (see this plunk).


  <li ng-repeat="item in listItems">
    <a ng-class="{'userActive': isActive, 'userInactive': !isActive}" ng-click="isActive = !isActive">L</a>

Read the entire recipe Recipe added 1 day ago