Showing posts with label AngularJS. Show all posts
Showing posts with label AngularJS. Show all posts

Wednesday, December 9, 2015

Create custom filter in AngularJS.

AngularJS Filter is nothing but a function returns a function used as an expression by pipe sign "|"; 
AngularJS provides some built-in filters such as  
- currency
- lowercase
- orderBy

and many others but you can create your own, if you need!   
Filters are simply takes an input and parameters, you process it and return the output.

How do you create your own custom filter? 


Here is a simple example.   

//.js 

var app = angular.module("myApp",[]);
app.filter("truncateString",function( ){
        return function(input, limit){
          limit = parseInt(limit);
           return (input.length > limit)?input.substring(0,limit):input;
    }
}); 

// usage in html.  
<span ng-bind="data.description | truncateString:'30'">,</span>


- truncateString filter will define limit to the text by parameter. 


   

Monday, November 23, 2015

ng-model is not working in ng-include in AngularJs

i have split my layout and used ng-include and noticed that my scope is suddenly stop working in ng-include!, to overcome this problem i used $parent  like this. 

<input type=text ng-model="$parent.Contact.EmailAddress" />

It works great!

Friday, November 13, 2015

Uncaught Error: [$injector:modulerr] AngularJS Error in console - Google Chrome.

While using routing in AngularJS, sometime we face this error in our console. 
 Uncaught Error: [$injector:modulerr]

The problem was caused by missing inclusion of ngRoute module. 

Reference this link to your page may solve this problem. 

  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular-route.min.js"></script>