i have a problem with ionic2 + angular ts + wordpress to create bookmark page. i dont understand, how to put current url of page, and then i want to assign url to localstorage so i can create bookmark of page. anyone can help ?
i have searching about this problem about 3 days, but i get nothing.
to get url i try with this code and test on console.
@Component({
selector: 'page-favorites',
templateUrl: 'favorites.html',
})
export class FavoritesPage {
url:string = this.navParams.get('url');
constructor(
public navCtrl: NavController,
public navParams: NavParams,
){
console.log(this.url);
}
the console say undefined
it's hard to give suggestions based on the information you give. What URL are you trying to save to your favourites?
navParams.get()
gets the parameters you passed when opening that page.
As an example, let's say you have a "Home" page and a "Favourites" page. When your app loads you see the home page. You can then add a link to the favourites page and pass it a parameter like that:
let data = 'test';
this.navCtrl.push(FavouritesPage, {
data: data
});
You can then get the value of the data parameter on the FavouritesPage like that:
constructor(...) {
this.navParams.get('data'); // This will be 'test'
}
You said that you work with Wordpress. So somewhere you will have a URL like "https://example.com/my/path/" or a unique ID. You need to pass that URL to the favourites page as described above. Or if you are trying to favourite a page in your app, I would instead pass a unique name and then use that name to open the according page (using an if/else).