Call ngAfterViewInit of Angular component from common place
I am using bootstrap tooltip.
I want to trigger ngAfterViewInit for every component from some common place.
Common place(like app.module.ts)
ngAfterViewInit() {
$('[data-toggle="tooltip"]').tooltip();
}
Component_1:
There is no ngAfterViewInit in component, still life cycle is trigger from some common place.
Component_2:
This component has ngAfterViewInit,
ngAfterViewInit() {
// Some extra functionality
}
In this case ngAfterViewInit is triggered from both the places(common place as well as from it's respective component)
Is there any way to achieve this?
Thanks
javascript

add a comment |
I am using bootstrap tooltip.
I want to trigger ngAfterViewInit for every component from some common place.
Common place(like app.module.ts)
ngAfterViewInit() {
$('[data-toggle="tooltip"]').tooltip();
}
Component_1:
There is no ngAfterViewInit in component, still life cycle is trigger from some common place.
Component_2:
This component has ngAfterViewInit,
ngAfterViewInit() {
// Some extra functionality
}
In this case ngAfterViewInit is triggered from both the places(common place as well as from it's respective component)
Is there any way to achieve this?
Thanks
javascript

AfterViewInit is an interface, just extends from a component class and use wherever you want to use
– Prashant Pimpale
Jan 1 at 7:06
A lifecycle hook that is called after Angular has fully initialized a component's view. Define a ngAfterViewInit() method to handle any additional initialization tasks. so each component has there owned responsibility
– Prashant Pimpale
Jan 1 at 7:07
add a comment |
I am using bootstrap tooltip.
I want to trigger ngAfterViewInit for every component from some common place.
Common place(like app.module.ts)
ngAfterViewInit() {
$('[data-toggle="tooltip"]').tooltip();
}
Component_1:
There is no ngAfterViewInit in component, still life cycle is trigger from some common place.
Component_2:
This component has ngAfterViewInit,
ngAfterViewInit() {
// Some extra functionality
}
In this case ngAfterViewInit is triggered from both the places(common place as well as from it's respective component)
Is there any way to achieve this?
Thanks
javascript

I am using bootstrap tooltip.
I want to trigger ngAfterViewInit for every component from some common place.
Common place(like app.module.ts)
ngAfterViewInit() {
$('[data-toggle="tooltip"]').tooltip();
}
Component_1:
There is no ngAfterViewInit in component, still life cycle is trigger from some common place.
Component_2:
This component has ngAfterViewInit,
ngAfterViewInit() {
// Some extra functionality
}
In this case ngAfterViewInit is triggered from both the places(common place as well as from it's respective component)
Is there any way to achieve this?
Thanks
javascript

javascript

asked Jan 1 at 7:00


AnkurAnkur
422319
422319
AfterViewInit is an interface, just extends from a component class and use wherever you want to use
– Prashant Pimpale
Jan 1 at 7:06
A lifecycle hook that is called after Angular has fully initialized a component's view. Define a ngAfterViewInit() method to handle any additional initialization tasks. so each component has there owned responsibility
– Prashant Pimpale
Jan 1 at 7:07
add a comment |
AfterViewInit is an interface, just extends from a component class and use wherever you want to use
– Prashant Pimpale
Jan 1 at 7:06
A lifecycle hook that is called after Angular has fully initialized a component's view. Define a ngAfterViewInit() method to handle any additional initialization tasks. so each component has there owned responsibility
– Prashant Pimpale
Jan 1 at 7:07
AfterViewInit is an interface, just extends from a component class and use wherever you want to use
– Prashant Pimpale
Jan 1 at 7:06
AfterViewInit is an interface, just extends from a component class and use wherever you want to use
– Prashant Pimpale
Jan 1 at 7:06
A lifecycle hook that is called after Angular has fully initialized a component's view. Define a ngAfterViewInit() method to handle any additional initialization tasks. so each component has there owned responsibility
– Prashant Pimpale
Jan 1 at 7:07
A lifecycle hook that is called after Angular has fully initialized a component's view. Define a ngAfterViewInit() method to handle any additional initialization tasks. so each component has there owned responsibility
– Prashant Pimpale
Jan 1 at 7:07
add a comment |
1 Answer
1
active
oldest
votes
There isn't "one common place" where you can define a global behavior for all of your components.
Instead, you can create the following class and make your desired components extend it:
export abstract class BaseComponent implements AfterViewInit {
/**
* View initialization behavior. Note that derived classes must not implement AfterViewInit .
* Use viewInit() on derived classes instead.
*/
ngAfterViewInit(): void {
// Your code
this.viewInit();
}
/**
* Function that allows derived components to define an additional view initialization behavior
*/
abstract viewInit(): void;
}
I think you misunderstood the question, I want some common place from where I can all the ngAfterViewInit. Not only from component. I want extra hook or listener.
– Ankur
Jan 5 at 4:17
@Ankur please take a look at my new answer
– YoukouleleY
Jan 7 at 17:41
add a comment |
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',
autoActivateHeartbeat: false,
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53993613%2fcall-ngafterviewinit-of-angular-component-from-common-place%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
There isn't "one common place" where you can define a global behavior for all of your components.
Instead, you can create the following class and make your desired components extend it:
export abstract class BaseComponent implements AfterViewInit {
/**
* View initialization behavior. Note that derived classes must not implement AfterViewInit .
* Use viewInit() on derived classes instead.
*/
ngAfterViewInit(): void {
// Your code
this.viewInit();
}
/**
* Function that allows derived components to define an additional view initialization behavior
*/
abstract viewInit(): void;
}
I think you misunderstood the question, I want some common place from where I can all the ngAfterViewInit. Not only from component. I want extra hook or listener.
– Ankur
Jan 5 at 4:17
@Ankur please take a look at my new answer
– YoukouleleY
Jan 7 at 17:41
add a comment |
There isn't "one common place" where you can define a global behavior for all of your components.
Instead, you can create the following class and make your desired components extend it:
export abstract class BaseComponent implements AfterViewInit {
/**
* View initialization behavior. Note that derived classes must not implement AfterViewInit .
* Use viewInit() on derived classes instead.
*/
ngAfterViewInit(): void {
// Your code
this.viewInit();
}
/**
* Function that allows derived components to define an additional view initialization behavior
*/
abstract viewInit(): void;
}
I think you misunderstood the question, I want some common place from where I can all the ngAfterViewInit. Not only from component. I want extra hook or listener.
– Ankur
Jan 5 at 4:17
@Ankur please take a look at my new answer
– YoukouleleY
Jan 7 at 17:41
add a comment |
There isn't "one common place" where you can define a global behavior for all of your components.
Instead, you can create the following class and make your desired components extend it:
export abstract class BaseComponent implements AfterViewInit {
/**
* View initialization behavior. Note that derived classes must not implement AfterViewInit .
* Use viewInit() on derived classes instead.
*/
ngAfterViewInit(): void {
// Your code
this.viewInit();
}
/**
* Function that allows derived components to define an additional view initialization behavior
*/
abstract viewInit(): void;
}
There isn't "one common place" where you can define a global behavior for all of your components.
Instead, you can create the following class and make your desired components extend it:
export abstract class BaseComponent implements AfterViewInit {
/**
* View initialization behavior. Note that derived classes must not implement AfterViewInit .
* Use viewInit() on derived classes instead.
*/
ngAfterViewInit(): void {
// Your code
this.viewInit();
}
/**
* Function that allows derived components to define an additional view initialization behavior
*/
abstract viewInit(): void;
}
edited Jan 7 at 17:40
answered Jan 1 at 21:11
YoukouleleYYoukouleleY
2,6961826
2,6961826
I think you misunderstood the question, I want some common place from where I can all the ngAfterViewInit. Not only from component. I want extra hook or listener.
– Ankur
Jan 5 at 4:17
@Ankur please take a look at my new answer
– YoukouleleY
Jan 7 at 17:41
add a comment |
I think you misunderstood the question, I want some common place from where I can all the ngAfterViewInit. Not only from component. I want extra hook or listener.
– Ankur
Jan 5 at 4:17
@Ankur please take a look at my new answer
– YoukouleleY
Jan 7 at 17:41
I think you misunderstood the question, I want some common place from where I can all the ngAfterViewInit. Not only from component. I want extra hook or listener.
– Ankur
Jan 5 at 4:17
I think you misunderstood the question, I want some common place from where I can all the ngAfterViewInit. Not only from component. I want extra hook or listener.
– Ankur
Jan 5 at 4:17
@Ankur please take a look at my new answer
– YoukouleleY
Jan 7 at 17:41
@Ankur please take a look at my new answer
– YoukouleleY
Jan 7 at 17:41
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53993613%2fcall-ngafterviewinit-of-angular-component-from-common-place%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
AfterViewInit is an interface, just extends from a component class and use wherever you want to use
– Prashant Pimpale
Jan 1 at 7:06
A lifecycle hook that is called after Angular has fully initialized a component's view. Define a ngAfterViewInit() method to handle any additional initialization tasks. so each component has there owned responsibility
– Prashant Pimpale
Jan 1 at 7:07