AngularJS logout not working with anonymous functions











up vote
0
down vote

favorite












I am working on AngularJS 1.5 project where I have to clear some settings before logout()



Working code (which does not clear settings)



this.logout = userSession.logout



  • userSession is a service which has logout


Modified code (which clears the settings but does not logout)



this.logout = () => {
mySettings.clear()
userSession.logout
}


Html Code:



<a href="" ng-click="$ctrl.logout()">
<span class="icon-logout"</span>
</a>









share|improve this question


















  • 1




    (stop editing it) in your function you need to actually call the method, so change userSession.logout to userSession.logout(), whereas before you were only referencing it
    – Aleksey Solovey
    Nov 7 at 15:50










  • @AlekseySolovey It is working, Thanks, But I don't understand why it was working with this.logout = userSession.logout (without parentheses)
    – Dot Net Dev
    Nov 7 at 15:59










  • once again, you were referencing it. With that code this.logout became a method, which you can call using this.logout(), or in HTML: $ctrl.logout()
    – Aleksey Solovey
    Nov 7 at 16:01












  • Ah understood, Thanks
    – Dot Net Dev
    Nov 7 at 16:03















up vote
0
down vote

favorite












I am working on AngularJS 1.5 project where I have to clear some settings before logout()



Working code (which does not clear settings)



this.logout = userSession.logout



  • userSession is a service which has logout


Modified code (which clears the settings but does not logout)



this.logout = () => {
mySettings.clear()
userSession.logout
}


Html Code:



<a href="" ng-click="$ctrl.logout()">
<span class="icon-logout"</span>
</a>









share|improve this question


















  • 1




    (stop editing it) in your function you need to actually call the method, so change userSession.logout to userSession.logout(), whereas before you were only referencing it
    – Aleksey Solovey
    Nov 7 at 15:50










  • @AlekseySolovey It is working, Thanks, But I don't understand why it was working with this.logout = userSession.logout (without parentheses)
    – Dot Net Dev
    Nov 7 at 15:59










  • once again, you were referencing it. With that code this.logout became a method, which you can call using this.logout(), or in HTML: $ctrl.logout()
    – Aleksey Solovey
    Nov 7 at 16:01












  • Ah understood, Thanks
    – Dot Net Dev
    Nov 7 at 16:03













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am working on AngularJS 1.5 project where I have to clear some settings before logout()



Working code (which does not clear settings)



this.logout = userSession.logout



  • userSession is a service which has logout


Modified code (which clears the settings but does not logout)



this.logout = () => {
mySettings.clear()
userSession.logout
}


Html Code:



<a href="" ng-click="$ctrl.logout()">
<span class="icon-logout"</span>
</a>









share|improve this question













I am working on AngularJS 1.5 project where I have to clear some settings before logout()



Working code (which does not clear settings)



this.logout = userSession.logout



  • userSession is a service which has logout


Modified code (which clears the settings but does not logout)



this.logout = () => {
mySettings.clear()
userSession.logout
}


Html Code:



<a href="" ng-click="$ctrl.logout()">
<span class="icon-logout"</span>
</a>






angularjs






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 7 at 15:46









Dot Net Dev

946




946








  • 1




    (stop editing it) in your function you need to actually call the method, so change userSession.logout to userSession.logout(), whereas before you were only referencing it
    – Aleksey Solovey
    Nov 7 at 15:50










  • @AlekseySolovey It is working, Thanks, But I don't understand why it was working with this.logout = userSession.logout (without parentheses)
    – Dot Net Dev
    Nov 7 at 15:59










  • once again, you were referencing it. With that code this.logout became a method, which you can call using this.logout(), or in HTML: $ctrl.logout()
    – Aleksey Solovey
    Nov 7 at 16:01












  • Ah understood, Thanks
    – Dot Net Dev
    Nov 7 at 16:03














  • 1




    (stop editing it) in your function you need to actually call the method, so change userSession.logout to userSession.logout(), whereas before you were only referencing it
    – Aleksey Solovey
    Nov 7 at 15:50










  • @AlekseySolovey It is working, Thanks, But I don't understand why it was working with this.logout = userSession.logout (without parentheses)
    – Dot Net Dev
    Nov 7 at 15:59










  • once again, you were referencing it. With that code this.logout became a method, which you can call using this.logout(), or in HTML: $ctrl.logout()
    – Aleksey Solovey
    Nov 7 at 16:01












  • Ah understood, Thanks
    – Dot Net Dev
    Nov 7 at 16:03








1




1




(stop editing it) in your function you need to actually call the method, so change userSession.logout to userSession.logout(), whereas before you were only referencing it
– Aleksey Solovey
Nov 7 at 15:50




(stop editing it) in your function you need to actually call the method, so change userSession.logout to userSession.logout(), whereas before you were only referencing it
– Aleksey Solovey
Nov 7 at 15:50












@AlekseySolovey It is working, Thanks, But I don't understand why it was working with this.logout = userSession.logout (without parentheses)
– Dot Net Dev
Nov 7 at 15:59




@AlekseySolovey It is working, Thanks, But I don't understand why it was working with this.logout = userSession.logout (without parentheses)
– Dot Net Dev
Nov 7 at 15:59












once again, you were referencing it. With that code this.logout became a method, which you can call using this.logout(), or in HTML: $ctrl.logout()
– Aleksey Solovey
Nov 7 at 16:01






once again, you were referencing it. With that code this.logout became a method, which you can call using this.logout(), or in HTML: $ctrl.logout()
– Aleksey Solovey
Nov 7 at 16:01














Ah understood, Thanks
– Dot Net Dev
Nov 7 at 16:03




Ah understood, Thanks
– Dot Net Dev
Nov 7 at 16:03












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










You forgot the parentheses when calling userSession.logout.



Should be:



this.logout = () => {
mySettings.clear()
userSession.logout(); // added parentheses
}





share|improve this answer





















  • It is working, Thanks, But I don't understand why it was working with this.logout = userSession.logout (without parentheses)
    – Dot Net Dev
    Nov 7 at 15:59











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',
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%2f53192906%2fangularjs-logout-not-working-with-anonymous-functions%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted










You forgot the parentheses when calling userSession.logout.



Should be:



this.logout = () => {
mySettings.clear()
userSession.logout(); // added parentheses
}





share|improve this answer





















  • It is working, Thanks, But I don't understand why it was working with this.logout = userSession.logout (without parentheses)
    – Dot Net Dev
    Nov 7 at 15:59















up vote
0
down vote



accepted










You forgot the parentheses when calling userSession.logout.



Should be:



this.logout = () => {
mySettings.clear()
userSession.logout(); // added parentheses
}





share|improve this answer





















  • It is working, Thanks, But I don't understand why it was working with this.logout = userSession.logout (without parentheses)
    – Dot Net Dev
    Nov 7 at 15:59













up vote
0
down vote



accepted







up vote
0
down vote



accepted






You forgot the parentheses when calling userSession.logout.



Should be:



this.logout = () => {
mySettings.clear()
userSession.logout(); // added parentheses
}





share|improve this answer












You forgot the parentheses when calling userSession.logout.



Should be:



this.logout = () => {
mySettings.clear()
userSession.logout(); // added parentheses
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 7 at 15:51









Victor P

7181020




7181020












  • It is working, Thanks, But I don't understand why it was working with this.logout = userSession.logout (without parentheses)
    – Dot Net Dev
    Nov 7 at 15:59


















  • It is working, Thanks, But I don't understand why it was working with this.logout = userSession.logout (without parentheses)
    – Dot Net Dev
    Nov 7 at 15:59
















It is working, Thanks, But I don't understand why it was working with this.logout = userSession.logout (without parentheses)
– Dot Net Dev
Nov 7 at 15:59




It is working, Thanks, But I don't understand why it was working with this.logout = userSession.logout (without parentheses)
– Dot Net Dev
Nov 7 at 15:59


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53192906%2fangularjs-logout-not-working-with-anonymous-functions%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







這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini