not able to send the data from one module component to another module component











up vote
0
down vote

favorite












I would like to send the boolean value to true to another module component where I shall set the *ngIf value to true to enable the html content. It's navigating to the another component, but not able to enable the html content. I have tried viewchild,emitters,input, output but not able to achieve the desired outcome.



Calling component:



SuccessGet(res) {
this.logs = res;

for(let item of this.logs)
{
if(item._email == this.log._email && item._password == this.log._password)
{
alert("Login Successful");

this.wt.LoginCall(true); // here calling the other module component
}
}

this.log = new LoginModel();
}


Called component:



export class WeatherComponent {
title = 'TemperatureApp';

//@Input() messagetochild_weather ;//to get the message from parent

showweather : boolean = false;
// showweather : boolean = false;

bus : BusinessLogic = new BusinessLogic();
WeatherModel : Weather = new Weather();
WeatherModels : Array<Weather> = new Array<Weather>();
num : number = 0;

LoginCall(item : boolean)
{
//this.ngAfterViewInit();
this.showweather = item;
}

ngAfterViewInit(item : any): void
{
this.WeatherModels = this.bus.Load();
}


HTML:



<div *ngIf=showweather class="card">//here i am using *ngIf
<h3 class="card-header text-center font-weight-bold text-uppercase py-4">Editable table</h3>
<div class="card-body">
<div id="table" class="table-editable">
<span class="table-add float-right mb-3 mr-2"><a href="#!" class="text-success"><i class="fa fa-plus fa-2x"
aria-hidden="true"></i></a></span>
<table class=" table table-bordered table-responsive-md table-striped text-center table-responsive-sm" style="border-block-end-color:dodgerblue">
<tr style="background-color: rgb(0, 255, 255)">
<th class="text-center">Area Code</th>
<th class="text-center" >Date</th>
<th class="text-center">Country</th>
<th class="text-center">State</th>
<th class="text-center">City</th>
<th class="text-center">Temperature</th>
<th class="text-center">Action</th>
<th class="text-center">Action</th>
</tr>









share|improve this question
























  • What is this.wt? Where is the *ngIf you're trying to use?
    – user184994
    Nov 11 at 12:29










  • @ user184994 : wt is an instance of the component to which i am calling. Edited the content to show the html content where i am using *ngIf.
    – Pradeep
    Nov 11 at 12:37












  • Interacting the with component directly is not the correct way to do it. Instead, you should create a service to handle the interaction, as suggeted by @SureshKumarAriya angular.io/guide/component-interaction
    – user184994
    Nov 11 at 13:09

















up vote
0
down vote

favorite












I would like to send the boolean value to true to another module component where I shall set the *ngIf value to true to enable the html content. It's navigating to the another component, but not able to enable the html content. I have tried viewchild,emitters,input, output but not able to achieve the desired outcome.



Calling component:



SuccessGet(res) {
this.logs = res;

for(let item of this.logs)
{
if(item._email == this.log._email && item._password == this.log._password)
{
alert("Login Successful");

this.wt.LoginCall(true); // here calling the other module component
}
}

this.log = new LoginModel();
}


Called component:



export class WeatherComponent {
title = 'TemperatureApp';

//@Input() messagetochild_weather ;//to get the message from parent

showweather : boolean = false;
// showweather : boolean = false;

bus : BusinessLogic = new BusinessLogic();
WeatherModel : Weather = new Weather();
WeatherModels : Array<Weather> = new Array<Weather>();
num : number = 0;

LoginCall(item : boolean)
{
//this.ngAfterViewInit();
this.showweather = item;
}

ngAfterViewInit(item : any): void
{
this.WeatherModels = this.bus.Load();
}


HTML:



<div *ngIf=showweather class="card">//here i am using *ngIf
<h3 class="card-header text-center font-weight-bold text-uppercase py-4">Editable table</h3>
<div class="card-body">
<div id="table" class="table-editable">
<span class="table-add float-right mb-3 mr-2"><a href="#!" class="text-success"><i class="fa fa-plus fa-2x"
aria-hidden="true"></i></a></span>
<table class=" table table-bordered table-responsive-md table-striped text-center table-responsive-sm" style="border-block-end-color:dodgerblue">
<tr style="background-color: rgb(0, 255, 255)">
<th class="text-center">Area Code</th>
<th class="text-center" >Date</th>
<th class="text-center">Country</th>
<th class="text-center">State</th>
<th class="text-center">City</th>
<th class="text-center">Temperature</th>
<th class="text-center">Action</th>
<th class="text-center">Action</th>
</tr>









share|improve this question
























  • What is this.wt? Where is the *ngIf you're trying to use?
    – user184994
    Nov 11 at 12:29










  • @ user184994 : wt is an instance of the component to which i am calling. Edited the content to show the html content where i am using *ngIf.
    – Pradeep
    Nov 11 at 12:37












  • Interacting the with component directly is not the correct way to do it. Instead, you should create a service to handle the interaction, as suggeted by @SureshKumarAriya angular.io/guide/component-interaction
    – user184994
    Nov 11 at 13:09















up vote
0
down vote

favorite









up vote
0
down vote

favorite











I would like to send the boolean value to true to another module component where I shall set the *ngIf value to true to enable the html content. It's navigating to the another component, but not able to enable the html content. I have tried viewchild,emitters,input, output but not able to achieve the desired outcome.



Calling component:



SuccessGet(res) {
this.logs = res;

for(let item of this.logs)
{
if(item._email == this.log._email && item._password == this.log._password)
{
alert("Login Successful");

this.wt.LoginCall(true); // here calling the other module component
}
}

this.log = new LoginModel();
}


Called component:



export class WeatherComponent {
title = 'TemperatureApp';

//@Input() messagetochild_weather ;//to get the message from parent

showweather : boolean = false;
// showweather : boolean = false;

bus : BusinessLogic = new BusinessLogic();
WeatherModel : Weather = new Weather();
WeatherModels : Array<Weather> = new Array<Weather>();
num : number = 0;

LoginCall(item : boolean)
{
//this.ngAfterViewInit();
this.showweather = item;
}

ngAfterViewInit(item : any): void
{
this.WeatherModels = this.bus.Load();
}


HTML:



<div *ngIf=showweather class="card">//here i am using *ngIf
<h3 class="card-header text-center font-weight-bold text-uppercase py-4">Editable table</h3>
<div class="card-body">
<div id="table" class="table-editable">
<span class="table-add float-right mb-3 mr-2"><a href="#!" class="text-success"><i class="fa fa-plus fa-2x"
aria-hidden="true"></i></a></span>
<table class=" table table-bordered table-responsive-md table-striped text-center table-responsive-sm" style="border-block-end-color:dodgerblue">
<tr style="background-color: rgb(0, 255, 255)">
<th class="text-center">Area Code</th>
<th class="text-center" >Date</th>
<th class="text-center">Country</th>
<th class="text-center">State</th>
<th class="text-center">City</th>
<th class="text-center">Temperature</th>
<th class="text-center">Action</th>
<th class="text-center">Action</th>
</tr>









share|improve this question















I would like to send the boolean value to true to another module component where I shall set the *ngIf value to true to enable the html content. It's navigating to the another component, but not able to enable the html content. I have tried viewchild,emitters,input, output but not able to achieve the desired outcome.



Calling component:



SuccessGet(res) {
this.logs = res;

for(let item of this.logs)
{
if(item._email == this.log._email && item._password == this.log._password)
{
alert("Login Successful");

this.wt.LoginCall(true); // here calling the other module component
}
}

this.log = new LoginModel();
}


Called component:



export class WeatherComponent {
title = 'TemperatureApp';

//@Input() messagetochild_weather ;//to get the message from parent

showweather : boolean = false;
// showweather : boolean = false;

bus : BusinessLogic = new BusinessLogic();
WeatherModel : Weather = new Weather();
WeatherModels : Array<Weather> = new Array<Weather>();
num : number = 0;

LoginCall(item : boolean)
{
//this.ngAfterViewInit();
this.showweather = item;
}

ngAfterViewInit(item : any): void
{
this.WeatherModels = this.bus.Load();
}


HTML:



<div *ngIf=showweather class="card">//here i am using *ngIf
<h3 class="card-header text-center font-weight-bold text-uppercase py-4">Editable table</h3>
<div class="card-body">
<div id="table" class="table-editable">
<span class="table-add float-right mb-3 mr-2"><a href="#!" class="text-success"><i class="fa fa-plus fa-2x"
aria-hidden="true"></i></a></span>
<table class=" table table-bordered table-responsive-md table-striped text-center table-responsive-sm" style="border-block-end-color:dodgerblue">
<tr style="background-color: rgb(0, 255, 255)">
<th class="text-center">Area Code</th>
<th class="text-center" >Date</th>
<th class="text-center">Country</th>
<th class="text-center">State</th>
<th class="text-center">City</th>
<th class="text-center">Temperature</th>
<th class="text-center">Action</th>
<th class="text-center">Action</th>
</tr>






angular angular5 angular6 angular2-routing angular2-forms






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 12:40









marc_s

567k12810971248




567k12810971248










asked Nov 11 at 12:16









Pradeep

13




13












  • What is this.wt? Where is the *ngIf you're trying to use?
    – user184994
    Nov 11 at 12:29










  • @ user184994 : wt is an instance of the component to which i am calling. Edited the content to show the html content where i am using *ngIf.
    – Pradeep
    Nov 11 at 12:37












  • Interacting the with component directly is not the correct way to do it. Instead, you should create a service to handle the interaction, as suggeted by @SureshKumarAriya angular.io/guide/component-interaction
    – user184994
    Nov 11 at 13:09




















  • What is this.wt? Where is the *ngIf you're trying to use?
    – user184994
    Nov 11 at 12:29










  • @ user184994 : wt is an instance of the component to which i am calling. Edited the content to show the html content where i am using *ngIf.
    – Pradeep
    Nov 11 at 12:37












  • Interacting the with component directly is not the correct way to do it. Instead, you should create a service to handle the interaction, as suggeted by @SureshKumarAriya angular.io/guide/component-interaction
    – user184994
    Nov 11 at 13:09


















What is this.wt? Where is the *ngIf you're trying to use?
– user184994
Nov 11 at 12:29




What is this.wt? Where is the *ngIf you're trying to use?
– user184994
Nov 11 at 12:29












@ user184994 : wt is an instance of the component to which i am calling. Edited the content to show the html content where i am using *ngIf.
– Pradeep
Nov 11 at 12:37






@ user184994 : wt is an instance of the component to which i am calling. Edited the content to show the html content where i am using *ngIf.
– Pradeep
Nov 11 at 12:37














Interacting the with component directly is not the correct way to do it. Instead, you should create a service to handle the interaction, as suggeted by @SureshKumarAriya angular.io/guide/component-interaction
– user184994
Nov 11 at 13:09






Interacting the with component directly is not the correct way to do it. Instead, you should create a service to handle the interaction, as suggeted by @SureshKumarAriya angular.io/guide/component-interaction
– user184994
Nov 11 at 13:09














1 Answer
1






active

oldest

votes

















up vote
1
down vote













You should use Subject/BehaviorSubject.



Service:



private statusValue = new Subject<Boolean>();
statusValue$ = this.statusValue.asObservable();

updateStatus(status){
this.statusValue.next(status);
}


Component 1:



this.service.updateStatus(true);


Component2:



this.service.statusValue$.subscribe(value=>{console.log(value);}





share|improve this answer





















    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%2f53248664%2fnot-able-to-send-the-data-from-one-module-component-to-another-module-component%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
    1
    down vote













    You should use Subject/BehaviorSubject.



    Service:



    private statusValue = new Subject<Boolean>();
    statusValue$ = this.statusValue.asObservable();

    updateStatus(status){
    this.statusValue.next(status);
    }


    Component 1:



    this.service.updateStatus(true);


    Component2:



    this.service.statusValue$.subscribe(value=>{console.log(value);}





    share|improve this answer

























      up vote
      1
      down vote













      You should use Subject/BehaviorSubject.



      Service:



      private statusValue = new Subject<Boolean>();
      statusValue$ = this.statusValue.asObservable();

      updateStatus(status){
      this.statusValue.next(status);
      }


      Component 1:



      this.service.updateStatus(true);


      Component2:



      this.service.statusValue$.subscribe(value=>{console.log(value);}





      share|improve this answer























        up vote
        1
        down vote










        up vote
        1
        down vote









        You should use Subject/BehaviorSubject.



        Service:



        private statusValue = new Subject<Boolean>();
        statusValue$ = this.statusValue.asObservable();

        updateStatus(status){
        this.statusValue.next(status);
        }


        Component 1:



        this.service.updateStatus(true);


        Component2:



        this.service.statusValue$.subscribe(value=>{console.log(value);}





        share|improve this answer












        You should use Subject/BehaviorSubject.



        Service:



        private statusValue = new Subject<Boolean>();
        statusValue$ = this.statusValue.asObservable();

        updateStatus(status){
        this.statusValue.next(status);
        }


        Component 1:



        this.service.updateStatus(true);


        Component2:



        this.service.statusValue$.subscribe(value=>{console.log(value);}






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 11 at 12:40









        Suresh Kumar Ariya

        4,0351215




        4,0351215






























            draft saved

            draft discarded




















































            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248664%2fnot-able-to-send-the-data-from-one-module-component-to-another-module-component%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







            Popular posts from this blog

            Full-time equivalent

            Bicuculline

            さくらももこ