Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Expressions(in templates) are not evaluated in $watch of custom directive of angularjs #1441

@abdulazeezsk

Description

@abdulazeezsk

This can be found here as well, http://stackoverflow.com/questions/12748392/expressions-are-not-evaluated-in-watch-of-custom-directive-of-angularjs

I have a below custom directive in angularjs which uses model thats gets updated from server, I have added a watch listener to watch the changes of that model,

var linkFn;
linkFn = function(scope, element, attrs) {
scope.$watch('$parent.photogallery', function(newValue, oldValue) {
if(angular.isUndefined(newValue)) {
return;
}
var $container = element;
alert($container.element);
$container.imagesLoaded(function() {
$container.masonry({
itemSelector : '.box'
});
});
});
};
return {
templateUrl:'templates/Photos_Masonry.htm',
replace: false,
transclude:true,
scope: {
photogallery: '=photoGallery',
},
restrict: 'A',
link: linkFn
However, when i debug in my watch directive, i still see that expressions in templates are still unresolved.i.e. photo.label, ng-src all are still unresolved. AFIK, $digest would be called only after $eval. Is this intended behavior? My jQuery calls are not working due to this? Is there any other event where i get the result element with evaluated expressions?

Here is my template, which has ng-repeat in it,

Stanley

{{galleryname}}

{{photo.seasonname}}

photogallery is initialized in parent controller,

function MyCtrlCampaign($scope, srvgallery, mygallery) {

$scope.updatedata = function() {
    $scope.photogallery     = srvgallery.getphotos($routeParams);
};

$scope.getphotos = function() {
    srvgallery.photos().success(function(data) {
        $scope.updatedata();
    }).error(function(data) {

    });
};

Directive is used in below way,

Kindly let me know your views on this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions