How to intercept end of data binding in Angular Js

I am developing a web application using Angular Js framework, with HTML5 and using jQuery when needed. The question arises:

I have several fields whose values ​​depend on the result of an AJAX call. This request returns JSON, and the fields of that JSON become the values ​​of many tags.

For example, in the HTML code, I:

<span>Data Nascita: <b><span id="patientBirthdate">{{patient.birthDate}}</span></b></span>

      

And in my controller I have this request:

$.ajax({
    type: "GET",
    url: url,
    async: true,
    crossDomain: true,
    success:function(result){
        $scope.person = result;

    },
    error: function(xhr,status,error){
        console.log ("error in receiving person data");
    }
});

      

This data binding is working correctly.

The question is, how can I intercept the end of the data binding operation (the end of filling the {{patient.birthDate}} field) to somehow call another javascript method on that field?

My goal is to "truncate" the value of this field after padding done by Angular using a jQuery plugin with a call of this type:

$("#patientBirthdate").shorten({showChars: 15, moreText: ' >>', lessText: ' <<'});  

      

Thanks in advance.

+3


source to share


1 answer


http://jsfiddle.net/SQuVy/751/ here you can do with $watch

.

whenever a change occurs, the object callback is called,

ex.



angular.module('watchApp', []).controller('watchCtrl', function($scope) {
    $scope.count = 0;

    $scope.$watch('a', function() {
        // change happened here do something
        $scope.b=$scope.a;

//OR you can call your method here

        }, true);
    });

      

I am here assigning the value of a to b when a is changed.

0


source







All Articles