Title: How to read "this" inside promise response in Angular
Tags: angular
Question: this.vendorService.getCities(e.id)
.then((d) =&gt; {
this.cityList = d.info;
}
});
when I check this.cityList in breakpoints it throw error but in console.log(this.cityList) it works fine .
I am using Angular-cli
Uncaught TypeError: Cannot read property 'cityList' of undefined
Comment: ^ This. You lost `this` in parent function scope.

Comment: Show your code where you call `this.vendorService.getCities`

Comment: see this answer https://stackoverflow.com/a/44739585/2545680



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 0, 'CommentCount': 3, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2017:00:09/13/17', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<angular>', 'Title': 'How to read "this" inside promise response in Angular', 'ViewCount': 67, 'id': 46195908, 'user_AboutMe': '<p><a href="https://www.facebook.com/Ajha1" rel="nofollow noreferrer">Connect me on Facebook</a></p>\n\n<p><a href="https://www.instagram.com/ashutosh_jha01/" rel="nofollow noreferrer">Connect me on Instagram</a></p>\n\n<p>For the past 4.5+ years, I\'ve been developing applications for the web using mostly JS. I do this for a living and love what I do as every day there is something new and exciting to learn.</p>\n\n<p>In my spare time, the web development community is a big part of my life. Whether managing online programming groups and blogs or attending a conference, I find keeping involved helps me stay up to date.</p>\n\n<p>This is also my chance to give back to the community that helped me get started, a place I am proud to be part of.</p>\n\n<p>I spend a lot of time learning new techniques and actively help other people learn web development through a variety of help groups and writing web development tutorials for my website and blog about advancements in web design and development.</p>\n', 'user_AccountId': 9602796.0, 'user_DisplayName': 'Ashutosh Jha', 'user_Reputation': 14121.0, 'user_Views': 724.0, 'user_id': 7129694.0}}