Angular updating and clearing factory variables

前端 未结 1 722
死守一世寂寞
死守一世寂寞 2021-01-22 20:30

I\'m creating a single page app in which a user searches for a term, the result gets saved in a variable, and a new page is routed that displays the result. I have this function

相关标签:
1条回答
  • 2021-01-22 20:58

    If you want it to wipe the value when they change routes (which logout should change routes also, I assume), you can watch the $routeChangeStart event and have it wipe the value whenever it occurs. You put that function in the module.run block:

    app.run(function ($rootScope, fact) { 
        $rootScope.$on("$routeChangeStart",function(event, next, current){
            fact.setInformation(null);
        });
    });
    
    0 讨论(0)
提交回复
热议问题