Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I try to update the list using directive template. But its not update the data after http request.

test.html:

<div ng-repeat=" comment in [{name:"A"},{name:"B"},{name:"C"}]">
    <div lookup-product-icon lookup="lookupProduct(comment)"   products="products"></div>
</div>
<div lookup-products></div>
....

Directive:

var app = angular.module('myApp');
app.directive('lookupProductIcon', function() {
    return {
        scope : {
            lookup : "&"
        },
        template : '<div  ng-click="lookup()">Use me!</div>',
    };
});

app.directive('lookupProducts', function() {
    return {
        restrict : 'EA',
        transclude : false,
        scope : {
            products : '='
        },
        templateUrl : 'lists.html'
    };
});

Controller

$scope.products = [];
        $scope.lookupProduct = function(lists) {
                var details = {
                name : lists.name,
                host : $scope.host_name
            };
            productService.lookupProduct(details).then(function(data) {
                $scope.products = data.list;
                console.log($scope.products);
                //Here display the lists in developer tools.
            }).catch(function(data) {
                if (data.message) {
                    alert(data.message);
                }
            });

        };

List.html:

<ul>
  <li ng-repeat = "product in products">    {{product.name}}    </li>
</ul>

Once I click the "Use me!" means then i need to send the http request and then display the lists for the respective content in list.html.

lookupProduct function working but only thing is the products not updating.

Details:

I added two directives. 1. lookupProductIcon - Display the text. Once this text clicked means need to the http get request and then response need to update in list.html (lookupProducts directive) 2. lookupProducts - Here the the data not updating.

share|improve this question
    
You define products inside lookup-products directive, but using in lookup-product-icon lookup. why? – vaqifrv Aug 2 at 9:44
    
I am using many pages this module. So i created lookup-product-icon. – RSKMR Aug 2 at 9:46
    
Are you shure lookup() is launched? The one on ng-click. I say that because in some cases I had to call $scope.apply() when I add dinamic directivies. – R3nPi2 Aug 2 at 9:53
    
I am sure i am getting the data after sucess. $scope.products = data.list; – RSKMR Aug 2 at 9:54
up vote 0 down vote accepted

Your lookupProducts directive has a scope variable products that is not being passed in your html markup.

You need to pass in an array of products to your lookupProducts directive.

<div lookup-products products="products"></div>

share|improve this answer
    
Oh god. Its my mistake only. Thanks – RSKMR Aug 2 at 11:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.