1

I have after ngOnInit 2 vars available items and title, items is for the view, i want to "execute" the setSeoTitle() function for the in the index.html, how can i achieve this?

items = [];
title = [];

ngOnInit() {
    this.dataService.fetchData(this.slug)
        .subscribe(
        (data) => {
            this.items = data;
            this.title = data;
        }
    );
}

setSeoTitle(item){
    this.seoService.setTitle(item[0]['title']);
}
1
  • Great, why downvoting? Not a good question? Commented Oct 24, 2016 at 5:25

3 Answers 3

3
ngOnInit() {
    this.dataService.fetchData(this.slug)
        .subscribe(
        (data) => {
            this.items = data;
            this.title = data;
            this.setSeoTitle(this.items ); ///<<###< here 
        }
    );
}
Sign up to request clarification or add additional context in comments.

1 Comment

that simple, great!
0
ngOnInit() {
    this.dataService.fetchData(this.slug)
        .subscribe(
        (data) => {
            this.items = data;
            this.title = data;
            this.setSeoTitle(this.item);
        }
    );
}

Comments

0
ngOnInit() {
    this.dataService.fetchData(this.slug)
        .subscribe(
        (data) => {
            this.items = data;
            this.title = data;
            this.setSeoTitle(this.items);
        }
    );
}

setSeoTitle(items){
  if (items.length) {
    this.seoService.setTitle(items[0]['title']);
  }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.