This topic contains 5 replies, has 3 voices, and was last updated by  lotus 1 week ago.

popover no working in ngFor variable which gets set via a API call


  • neelsaraiya
    Participant

    Posts: 4
    Member Reply #19207

    Please see attachment of my code to generate button popover in a ngFOR

    The allQuestionList gets set via a API Call

    If I just return _allQuestionList = [1,2,3,4] on ine 1 of the function;

    It will create 4 buttons with working popover. But if I do a http api call the popovers dont work. Please help

    • This topic was modified 9 months, 2 weeks ago by  neelsaraiya.
    Attachments:
    You must be logged in to view attached files.
    Jai
    Jai
    Keymaster

    Posts: 2715
    Support Staff Reply #19227

    Hi 🙂

    Can you try to init the popover after view init?

    ngAfterViewInit() {
    mApp.initPopovers();
    }

    Thanks


    neelsaraiya
    Participant

    Posts: 4
    Member Reply #19232

    Hi Jai,

    Thanks for your reply. Do I have to import any library into my component to use the function initPopovers() ?

    Not a angular expert here. appreciate your help.

    Neel


    neelsaraiya
    Participant

    Posts: 4
    Member Reply #19234

    Hi Jai,

    I have modified the script.bundle.js to add some console errors.

    the log always prints “here” but never prints $(this)

    The only way I can get it work is if I add a delay in the ngAfterViewInit

    ngAfterViewInit() {
    $timeout(function() {}, 2000);
    mApp.initPopovers();
    }

    var initPopovers = function() {
    console.log(‘here’);
    // init bootstrap popover
    $(‘[data-toggle=”m-popover”]’).each(function() {
    console.log($(this));
    initPopover($(this));
    });
    }

    Not a robust solution in my opinion. Hoping you can help me out with a better solution.

    Jai
    Jai
    Keymaster

    Posts: 2715
    Support Staff Reply #19257

    Hi 🙂

    Can you move mApp.initPopovers(); inside subscribe, after getting this._allQuestionList

    Thanks


    lotus
    Participant

    Posts: 5
    Member Reply #20095

    What does this line

    initPopover($(this));

    supposed to do? I am attempting to try this method as I have a list of data that I get from an angular custom library (that we built using Angular 7), this custom library gets the data via httpClient call, just an FYI.

    So in the implementation project (which is also Angular 7), I am following along to call the initPopovers right after I get the data. But I am wondering what this individual initPopover($(this)); is supposed to do. Can you please respond to me on that? Also a fragment of the html would be good in addition.

    TIA.

    P.S. in my case I need to show the popover on hover.

    • This reply was modified 1 week ago by  lotus. Reason: Just to remove the markup that wasn't intended
    • This reply was modified 1 week ago by  lotus.

You must be logged in to reply to this topic.