Angular7 - view doesnt get updated when using debouncerAngular 2 - View not updating after model changesAngular2 async callsPerformance of Observable Data Service in Angular/NativeScriptcorrect way to append objects to array in angular callbackAcquireToken Observable errors before returning tokenPlaceholder in mat-autoComplete does not work as illustrated in the Angular Material DocumentationAngular 6+ TypeError: Cannot read property 'firstName' of undefinedObservables: Creating a mock http requestAngular7 Element with Components getting Schema errorI am not getting the textbox value in typescript angular7

Why is Mitch McConnell blocking nominees to the Federal Election Commission?

Why don't "echo -e" commands seem to produce the right output?

Ways you can end up paying interest on a credit card if you pay the full amount back in due time

Was there an original & definitive use of alternate dimensions/realities in fiction?

How can I improve my formal definitions?

Could these polynomials be identified?

Received email from ISP saying one of my devices has malware

How are the cards determined in an incomplete deck of many things?

Are there balance issues when allowing attack of opportunity against any creature?

Polarity of gas discharge tubes?

Why do modes sound so different, although they are basically the same as a mode of another scale?

Why wasn't Linda Hamilton in T3?

How can an F-22 Raptor reach supersonic speeds without having supersonic inlets?

Pandas transform inconsistent behavior for list

Blender - Alpha is Luminance equivalent

Can a system of three stars exist?

Are there consequences for not filing a DMCA (any country)

Squares inside a square

Function of the separated, individual solar cells on Telstar 1 and 2? Why were they "special"?

Tikz: Draw simplified BLE-Stack

Am I required to correct my opponent's assumptions about my morph creatures?

Is the equational theory of groups axiomatized by the associative law?

Do universities maintain secret textbooks?

To minimize the Hausdorff distance between convex polygonal regions



Angular7 - view doesnt get updated when using debouncer


Angular 2 - View not updating after model changesAngular2 async callsPerformance of Observable Data Service in Angular/NativeScriptcorrect way to append objects to array in angular callbackAcquireToken Observable errors before returning tokenPlaceholder in mat-autoComplete does not work as illustrated in the Angular Material DocumentationAngular 6+ TypeError: Cannot read property 'firstName' of undefinedObservables: Creating a mock http requestAngular7 Element with Components getting Schema errorI am not getting the textbox value in typescript angular7






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I have this search service:



export class SearchbarComponent implements OnInit 
data: Observable<any>;
search = new FormControl();

constructor(private searchService: SearchbarService)

ngOnInit()
this.data = this.search.valueChanges
.pipe(
debounceTime(1),
distinctUntilChanged(),
)
.pipe(switchMap(search =>
this.searchService.getSearchResults(search)));




In the view I do something like this



<input placeholder="Search users here" [formControl]="search" />

<div *ngFor="let d of (data | async)" >
d.name
</div>



it works great but only on the first time but after showing the first result, the view doesnt get updated after that.



What am I doing wrong?










share|improve this question


























  • Shouldn't be this.data = this.search.valueChanges instead of this.users = this.search.valueChanges?

    – dcg
    Mar 28 at 0:31












  • Yes sorry that should be data. I will update my question. Though the main problem still persists

    – codeninja
    Mar 28 at 0:31


















1















I have this search service:



export class SearchbarComponent implements OnInit 
data: Observable<any>;
search = new FormControl();

constructor(private searchService: SearchbarService)

ngOnInit()
this.data = this.search.valueChanges
.pipe(
debounceTime(1),
distinctUntilChanged(),
)
.pipe(switchMap(search =>
this.searchService.getSearchResults(search)));




In the view I do something like this



<input placeholder="Search users here" [formControl]="search" />

<div *ngFor="let d of (data | async)" >
d.name
</div>



it works great but only on the first time but after showing the first result, the view doesnt get updated after that.



What am I doing wrong?










share|improve this question


























  • Shouldn't be this.data = this.search.valueChanges instead of this.users = this.search.valueChanges?

    – dcg
    Mar 28 at 0:31












  • Yes sorry that should be data. I will update my question. Though the main problem still persists

    – codeninja
    Mar 28 at 0:31














1












1








1








I have this search service:



export class SearchbarComponent implements OnInit 
data: Observable<any>;
search = new FormControl();

constructor(private searchService: SearchbarService)

ngOnInit()
this.data = this.search.valueChanges
.pipe(
debounceTime(1),
distinctUntilChanged(),
)
.pipe(switchMap(search =>
this.searchService.getSearchResults(search)));




In the view I do something like this



<input placeholder="Search users here" [formControl]="search" />

<div *ngFor="let d of (data | async)" >
d.name
</div>



it works great but only on the first time but after showing the first result, the view doesnt get updated after that.



What am I doing wrong?










share|improve this question
















I have this search service:



export class SearchbarComponent implements OnInit 
data: Observable<any>;
search = new FormControl();

constructor(private searchService: SearchbarService)

ngOnInit()
this.data = this.search.valueChanges
.pipe(
debounceTime(1),
distinctUntilChanged(),
)
.pipe(switchMap(search =>
this.searchService.getSearchResults(search)));




In the view I do something like this



<input placeholder="Search users here" [formControl]="search" />

<div *ngFor="let d of (data | async)" >
d.name
</div>



it works great but only on the first time but after showing the first result, the view doesnt get updated after that.



What am I doing wrong?







angular typescript






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 2:09









malbarmawi

8,8823 gold badges20 silver badges44 bronze badges




8,8823 gold badges20 silver badges44 bronze badges










asked Mar 28 at 0:28









codeninjacodeninja

63 bronze badges




63 bronze badges















  • Shouldn't be this.data = this.search.valueChanges instead of this.users = this.search.valueChanges?

    – dcg
    Mar 28 at 0:31












  • Yes sorry that should be data. I will update my question. Though the main problem still persists

    – codeninja
    Mar 28 at 0:31


















  • Shouldn't be this.data = this.search.valueChanges instead of this.users = this.search.valueChanges?

    – dcg
    Mar 28 at 0:31












  • Yes sorry that should be data. I will update my question. Though the main problem still persists

    – codeninja
    Mar 28 at 0:31

















Shouldn't be this.data = this.search.valueChanges instead of this.users = this.search.valueChanges?

– dcg
Mar 28 at 0:31






Shouldn't be this.data = this.search.valueChanges instead of this.users = this.search.valueChanges?

– dcg
Mar 28 at 0:31














Yes sorry that should be data. I will update my question. Though the main problem still persists

– codeninja
Mar 28 at 0:31






Yes sorry that should be data. I will update my question. Though the main problem still persists

– codeninja
Mar 28 at 0:31













2 Answers
2






active

oldest

votes


















0















Try this 👍



.html



<input placeholder="Search users here" (keyup)="searchTerm$.next($event.target.value)"/>


.ts



import Observable from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/debounceTime';
import 'rxjs/add/operator/distinctUntilChanged';
import 'rxjs/add/operator/switchMap';


export class SearchbarComponent implements OnInit

searchTerm$ = new Subject<string>(); // <==== new

constructor(private searchService: SearchbarService)

ngOnInit()
this.searchTerm$.subscribe( term =>
this.searchService.getSearchResults(q)
)








share|improve this answer



























  • Hmm this doesn't do anything. The service is not getting called at all

    – codeninja
    Mar 28 at 1:49











  • @codeninja Now works

    – George C.
    Mar 28 at 1:56











  • @GeorgeC. Nope, still same issue :/

    – Software Ninja
    Mar 28 at 1:59











  • @GeorgeC. I created a stackblitz. Check it out stackblitz.com/edit/…

    – Software Ninja
    Mar 28 at 2:05



















0















I have create a working example base in your code the only difference between yours and mine is the service check mine



@Injectable()
export class SearchbarService

constructor()

public getSearchResults(value)
const arr = [1,2,3,4,5,6]
return of([...arr.map(c=> Math.floor(Math.random() * 100))]); // return an observable





stackblitz demo






share|improve this answer



























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55388453%2fangular7-view-doesnt-get-updated-when-using-debouncer%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0















    Try this 👍



    .html



    <input placeholder="Search users here" (keyup)="searchTerm$.next($event.target.value)"/>


    .ts



    import Observable from 'rxjs/Observable';
    import 'rxjs/add/operator/map';
    import 'rxjs/add/operator/debounceTime';
    import 'rxjs/add/operator/distinctUntilChanged';
    import 'rxjs/add/operator/switchMap';


    export class SearchbarComponent implements OnInit

    searchTerm$ = new Subject<string>(); // <==== new

    constructor(private searchService: SearchbarService)

    ngOnInit()
    this.searchTerm$.subscribe( term =>
    this.searchService.getSearchResults(q)
    )








    share|improve this answer



























    • Hmm this doesn't do anything. The service is not getting called at all

      – codeninja
      Mar 28 at 1:49











    • @codeninja Now works

      – George C.
      Mar 28 at 1:56











    • @GeorgeC. Nope, still same issue :/

      – Software Ninja
      Mar 28 at 1:59











    • @GeorgeC. I created a stackblitz. Check it out stackblitz.com/edit/…

      – Software Ninja
      Mar 28 at 2:05
















    0















    Try this 👍



    .html



    <input placeholder="Search users here" (keyup)="searchTerm$.next($event.target.value)"/>


    .ts



    import Observable from 'rxjs/Observable';
    import 'rxjs/add/operator/map';
    import 'rxjs/add/operator/debounceTime';
    import 'rxjs/add/operator/distinctUntilChanged';
    import 'rxjs/add/operator/switchMap';


    export class SearchbarComponent implements OnInit

    searchTerm$ = new Subject<string>(); // <==== new

    constructor(private searchService: SearchbarService)

    ngOnInit()
    this.searchTerm$.subscribe( term =>
    this.searchService.getSearchResults(q)
    )








    share|improve this answer



























    • Hmm this doesn't do anything. The service is not getting called at all

      – codeninja
      Mar 28 at 1:49











    • @codeninja Now works

      – George C.
      Mar 28 at 1:56











    • @GeorgeC. Nope, still same issue :/

      – Software Ninja
      Mar 28 at 1:59











    • @GeorgeC. I created a stackblitz. Check it out stackblitz.com/edit/…

      – Software Ninja
      Mar 28 at 2:05














    0














    0










    0









    Try this 👍



    .html



    <input placeholder="Search users here" (keyup)="searchTerm$.next($event.target.value)"/>


    .ts



    import Observable from 'rxjs/Observable';
    import 'rxjs/add/operator/map';
    import 'rxjs/add/operator/debounceTime';
    import 'rxjs/add/operator/distinctUntilChanged';
    import 'rxjs/add/operator/switchMap';


    export class SearchbarComponent implements OnInit

    searchTerm$ = new Subject<string>(); // <==== new

    constructor(private searchService: SearchbarService)

    ngOnInit()
    this.searchTerm$.subscribe( term =>
    this.searchService.getSearchResults(q)
    )








    share|improve this answer















    Try this 👍



    .html



    <input placeholder="Search users here" (keyup)="searchTerm$.next($event.target.value)"/>


    .ts



    import Observable from 'rxjs/Observable';
    import 'rxjs/add/operator/map';
    import 'rxjs/add/operator/debounceTime';
    import 'rxjs/add/operator/distinctUntilChanged';
    import 'rxjs/add/operator/switchMap';


    export class SearchbarComponent implements OnInit

    searchTerm$ = new Subject<string>(); // <==== new

    constructor(private searchService: SearchbarService)

    ngOnInit()
    this.searchTerm$.subscribe( term =>
    this.searchService.getSearchResults(q)
    )









    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Mar 28 at 1:56

























    answered Mar 28 at 1:15









    George C.George C.

    1,7883 gold badges24 silver badges53 bronze badges




    1,7883 gold badges24 silver badges53 bronze badges















    • Hmm this doesn't do anything. The service is not getting called at all

      – codeninja
      Mar 28 at 1:49











    • @codeninja Now works

      – George C.
      Mar 28 at 1:56











    • @GeorgeC. Nope, still same issue :/

      – Software Ninja
      Mar 28 at 1:59











    • @GeorgeC. I created a stackblitz. Check it out stackblitz.com/edit/…

      – Software Ninja
      Mar 28 at 2:05


















    • Hmm this doesn't do anything. The service is not getting called at all

      – codeninja
      Mar 28 at 1:49











    • @codeninja Now works

      – George C.
      Mar 28 at 1:56











    • @GeorgeC. Nope, still same issue :/

      – Software Ninja
      Mar 28 at 1:59











    • @GeorgeC. I created a stackblitz. Check it out stackblitz.com/edit/…

      – Software Ninja
      Mar 28 at 2:05

















    Hmm this doesn't do anything. The service is not getting called at all

    – codeninja
    Mar 28 at 1:49





    Hmm this doesn't do anything. The service is not getting called at all

    – codeninja
    Mar 28 at 1:49













    @codeninja Now works

    – George C.
    Mar 28 at 1:56





    @codeninja Now works

    – George C.
    Mar 28 at 1:56













    @GeorgeC. Nope, still same issue :/

    – Software Ninja
    Mar 28 at 1:59





    @GeorgeC. Nope, still same issue :/

    – Software Ninja
    Mar 28 at 1:59













    @GeorgeC. I created a stackblitz. Check it out stackblitz.com/edit/…

    – Software Ninja
    Mar 28 at 2:05






    @GeorgeC. I created a stackblitz. Check it out stackblitz.com/edit/…

    – Software Ninja
    Mar 28 at 2:05














    0















    I have create a working example base in your code the only difference between yours and mine is the service check mine



    @Injectable()
    export class SearchbarService

    constructor()

    public getSearchResults(value)
    const arr = [1,2,3,4,5,6]
    return of([...arr.map(c=> Math.floor(Math.random() * 100))]); // return an observable





    stackblitz demo






    share|improve this answer





























      0















      I have create a working example base in your code the only difference between yours and mine is the service check mine



      @Injectable()
      export class SearchbarService

      constructor()

      public getSearchResults(value)
      const arr = [1,2,3,4,5,6]
      return of([...arr.map(c=> Math.floor(Math.random() * 100))]); // return an observable





      stackblitz demo






      share|improve this answer



























        0














        0










        0









        I have create a working example base in your code the only difference between yours and mine is the service check mine



        @Injectable()
        export class SearchbarService

        constructor()

        public getSearchResults(value)
        const arr = [1,2,3,4,5,6]
        return of([...arr.map(c=> Math.floor(Math.random() * 100))]); // return an observable





        stackblitz demo






        share|improve this answer













        I have create a working example base in your code the only difference between yours and mine is the service check mine



        @Injectable()
        export class SearchbarService

        constructor()

        public getSearchResults(value)
        const arr = [1,2,3,4,5,6]
        return of([...arr.map(c=> Math.floor(Math.random() * 100))]); // return an observable





        stackblitz demo







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 28 at 2:21









        malbarmawimalbarmawi

        8,8823 gold badges20 silver badges44 bronze badges




        8,8823 gold badges20 silver badges44 bronze badges






























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55388453%2fangular7-view-doesnt-get-updated-when-using-debouncer%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현