Posts

Showing posts with the label Directive

AngularJs -Effective way to Monitor Changes to Model data

Image
The two-way data binding in AngularJS is very powerful, especially when there is a direct mapping of input data to view-model-data. But, when the data mapping requires some translation, interpretation, or validation, you need to get your hands a little dirty - you need to get more involved in how data changes are propagated within your Controller(s). As this has happened to me, I've been forced to think more deeply about my AngularJS application architecture; and, as a result, I've found that my life is often simplified (in the long term) by calling a directive to watch before I bind the data to View model. Factory To Monitor Changes This is easiest and effective way because of these reasons : 1) I just need to call a Trigger Method with scope which should be monitored 2) Once the data is retrieved from Ajax call , I just Initialize the data 3) If there are any changes to bound data on the form and user tries to navigate to another page, I get Confirm box on the

Make it Easy by Angular-JS Directive to Format or Filter Date

Image
There is always a havoc on handling dates in the application either it's java /dot net or angular . So here is the best way I found in order to overcome the problem . Date Directive Here I am going to explain about angular date filtering concept and how to  use filtering concept to filter Date across your application.It is always better to create a date.js file for those filtering concept.  The advantage of this is you can very easily filter the data anywhere in your view by just placing directive. This can be achieved by using following code in your module defined, for example : CYW.date below. angular.module('CYW.date', []) .filter('stringToDate', function () { return function (input) { /// gets Date input, if not, returns null. Also sets the date to /// correct format if (!input) return null; var date = moment(input); return date.isValid() ? date.format('MM/DD/YYYY') : null; }; }