Angular - Value not being passed to Modal view












0















I am trying to pass through a value to a modal component, I followed this tutorial: https://itnext.io/creating-forms-inside-modals-with-ng-bootstrap-221e4f1f5648.



I can see the value being passed through, but not being retained on the other side. Any ideas why?



// Component being sent from 

openModal(millerIndex: number, farmIndex: number, view: number, millerName: string) {
const modalRef = this.modalService.open(ModalComponent);
modalRef.componentInstance.millerIndex = millerIndex;
modalRef.componentInstance.farmIndex = farmIndex;
modalRef.componentInstance.view = view;
modalRef.componentInstance.millerName = millerName;

modalRef.result.then((result) => {
console.log(result);
}).catch((error) => {
console.log(error);
});
}

// Modal component with relevant imports

@Input() millerIndex: number;
@Input() farmIndex: number;
@Input() view: number;
@Input() millerName: string;
@Input() farmName: string;
modalTitle = '';

// Being called OnInit()
createForm() {
if (this.view === 1) {

this.myForm = this.formBuilder.group({
paddockCode: new FormControl('', Validators.required),
paddockArea: new FormControl('', Validators.required),
paddockOwner: new FormControl({value: this.farmName, disabled:
true}, Validators.required)
});
}

// HTML inside form
<div class="form-group">
<label for="paddock-owner">Owner</label>
<input type="text" class="form-control"
formControlName="paddockOwner" value="{{ farmName }}" />
</div>









share|improve this question























  • Using ngModel on Reactive Forms has been deprecated in Angular 6 and will be removed in Angular 7. I just want to display the value, but when I console.log the value it's undefined. But, being passed through as part of the modalRef the value is there.

    – jmckie
    Nov 21 '18 at 2:04











  • I don't think you can use value on a form control when using reactive forms - you've already set it in code. And can you add your code which closes the model and passes the result back (assuming thats the console.log function you are referring to).

    – Dale Burrell
    Nov 21 '18 at 2:12













  • Inside the createFrom method I console.log the value and as mentioned it's undefined.

    – jmckie
    Nov 21 '18 at 2:15






  • 1





    Can you please update your code... the code you have shown doesn't include passing the farmName in, and is missing the console.log you refer to. It makes it hard to help.

    – Dale Burrell
    Nov 21 '18 at 2:17











  • Thanks Dale I didn't realise I hadn't passed through the farmName!

    – jmckie
    Nov 21 '18 at 2:20
















0















I am trying to pass through a value to a modal component, I followed this tutorial: https://itnext.io/creating-forms-inside-modals-with-ng-bootstrap-221e4f1f5648.



I can see the value being passed through, but not being retained on the other side. Any ideas why?



// Component being sent from 

openModal(millerIndex: number, farmIndex: number, view: number, millerName: string) {
const modalRef = this.modalService.open(ModalComponent);
modalRef.componentInstance.millerIndex = millerIndex;
modalRef.componentInstance.farmIndex = farmIndex;
modalRef.componentInstance.view = view;
modalRef.componentInstance.millerName = millerName;

modalRef.result.then((result) => {
console.log(result);
}).catch((error) => {
console.log(error);
});
}

// Modal component with relevant imports

@Input() millerIndex: number;
@Input() farmIndex: number;
@Input() view: number;
@Input() millerName: string;
@Input() farmName: string;
modalTitle = '';

// Being called OnInit()
createForm() {
if (this.view === 1) {

this.myForm = this.formBuilder.group({
paddockCode: new FormControl('', Validators.required),
paddockArea: new FormControl('', Validators.required),
paddockOwner: new FormControl({value: this.farmName, disabled:
true}, Validators.required)
});
}

// HTML inside form
<div class="form-group">
<label for="paddock-owner">Owner</label>
<input type="text" class="form-control"
formControlName="paddockOwner" value="{{ farmName }}" />
</div>









share|improve this question























  • Using ngModel on Reactive Forms has been deprecated in Angular 6 and will be removed in Angular 7. I just want to display the value, but when I console.log the value it's undefined. But, being passed through as part of the modalRef the value is there.

    – jmckie
    Nov 21 '18 at 2:04











  • I don't think you can use value on a form control when using reactive forms - you've already set it in code. And can you add your code which closes the model and passes the result back (assuming thats the console.log function you are referring to).

    – Dale Burrell
    Nov 21 '18 at 2:12













  • Inside the createFrom method I console.log the value and as mentioned it's undefined.

    – jmckie
    Nov 21 '18 at 2:15






  • 1





    Can you please update your code... the code you have shown doesn't include passing the farmName in, and is missing the console.log you refer to. It makes it hard to help.

    – Dale Burrell
    Nov 21 '18 at 2:17











  • Thanks Dale I didn't realise I hadn't passed through the farmName!

    – jmckie
    Nov 21 '18 at 2:20














0












0








0








I am trying to pass through a value to a modal component, I followed this tutorial: https://itnext.io/creating-forms-inside-modals-with-ng-bootstrap-221e4f1f5648.



I can see the value being passed through, but not being retained on the other side. Any ideas why?



// Component being sent from 

openModal(millerIndex: number, farmIndex: number, view: number, millerName: string) {
const modalRef = this.modalService.open(ModalComponent);
modalRef.componentInstance.millerIndex = millerIndex;
modalRef.componentInstance.farmIndex = farmIndex;
modalRef.componentInstance.view = view;
modalRef.componentInstance.millerName = millerName;

modalRef.result.then((result) => {
console.log(result);
}).catch((error) => {
console.log(error);
});
}

// Modal component with relevant imports

@Input() millerIndex: number;
@Input() farmIndex: number;
@Input() view: number;
@Input() millerName: string;
@Input() farmName: string;
modalTitle = '';

// Being called OnInit()
createForm() {
if (this.view === 1) {

this.myForm = this.formBuilder.group({
paddockCode: new FormControl('', Validators.required),
paddockArea: new FormControl('', Validators.required),
paddockOwner: new FormControl({value: this.farmName, disabled:
true}, Validators.required)
});
}

// HTML inside form
<div class="form-group">
<label for="paddock-owner">Owner</label>
<input type="text" class="form-control"
formControlName="paddockOwner" value="{{ farmName }}" />
</div>









share|improve this question














I am trying to pass through a value to a modal component, I followed this tutorial: https://itnext.io/creating-forms-inside-modals-with-ng-bootstrap-221e4f1f5648.



I can see the value being passed through, but not being retained on the other side. Any ideas why?



// Component being sent from 

openModal(millerIndex: number, farmIndex: number, view: number, millerName: string) {
const modalRef = this.modalService.open(ModalComponent);
modalRef.componentInstance.millerIndex = millerIndex;
modalRef.componentInstance.farmIndex = farmIndex;
modalRef.componentInstance.view = view;
modalRef.componentInstance.millerName = millerName;

modalRef.result.then((result) => {
console.log(result);
}).catch((error) => {
console.log(error);
});
}

// Modal component with relevant imports

@Input() millerIndex: number;
@Input() farmIndex: number;
@Input() view: number;
@Input() millerName: string;
@Input() farmName: string;
modalTitle = '';

// Being called OnInit()
createForm() {
if (this.view === 1) {

this.myForm = this.formBuilder.group({
paddockCode: new FormControl('', Validators.required),
paddockArea: new FormControl('', Validators.required),
paddockOwner: new FormControl({value: this.farmName, disabled:
true}, Validators.required)
});
}

// HTML inside form
<div class="form-group">
<label for="paddock-owner">Owner</label>
<input type="text" class="form-control"
formControlName="paddockOwner" value="{{ farmName }}" />
</div>






angular






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 1:11









jmckiejmckie

1069




1069













  • Using ngModel on Reactive Forms has been deprecated in Angular 6 and will be removed in Angular 7. I just want to display the value, but when I console.log the value it's undefined. But, being passed through as part of the modalRef the value is there.

    – jmckie
    Nov 21 '18 at 2:04











  • I don't think you can use value on a form control when using reactive forms - you've already set it in code. And can you add your code which closes the model and passes the result back (assuming thats the console.log function you are referring to).

    – Dale Burrell
    Nov 21 '18 at 2:12













  • Inside the createFrom method I console.log the value and as mentioned it's undefined.

    – jmckie
    Nov 21 '18 at 2:15






  • 1





    Can you please update your code... the code you have shown doesn't include passing the farmName in, and is missing the console.log you refer to. It makes it hard to help.

    – Dale Burrell
    Nov 21 '18 at 2:17











  • Thanks Dale I didn't realise I hadn't passed through the farmName!

    – jmckie
    Nov 21 '18 at 2:20



















  • Using ngModel on Reactive Forms has been deprecated in Angular 6 and will be removed in Angular 7. I just want to display the value, but when I console.log the value it's undefined. But, being passed through as part of the modalRef the value is there.

    – jmckie
    Nov 21 '18 at 2:04











  • I don't think you can use value on a form control when using reactive forms - you've already set it in code. And can you add your code which closes the model and passes the result back (assuming thats the console.log function you are referring to).

    – Dale Burrell
    Nov 21 '18 at 2:12













  • Inside the createFrom method I console.log the value and as mentioned it's undefined.

    – jmckie
    Nov 21 '18 at 2:15






  • 1





    Can you please update your code... the code you have shown doesn't include passing the farmName in, and is missing the console.log you refer to. It makes it hard to help.

    – Dale Burrell
    Nov 21 '18 at 2:17











  • Thanks Dale I didn't realise I hadn't passed through the farmName!

    – jmckie
    Nov 21 '18 at 2:20

















Using ngModel on Reactive Forms has been deprecated in Angular 6 and will be removed in Angular 7. I just want to display the value, but when I console.log the value it's undefined. But, being passed through as part of the modalRef the value is there.

– jmckie
Nov 21 '18 at 2:04





Using ngModel on Reactive Forms has been deprecated in Angular 6 and will be removed in Angular 7. I just want to display the value, but when I console.log the value it's undefined. But, being passed through as part of the modalRef the value is there.

– jmckie
Nov 21 '18 at 2:04













I don't think you can use value on a form control when using reactive forms - you've already set it in code. And can you add your code which closes the model and passes the result back (assuming thats the console.log function you are referring to).

– Dale Burrell
Nov 21 '18 at 2:12







I don't think you can use value on a form control when using reactive forms - you've already set it in code. And can you add your code which closes the model and passes the result back (assuming thats the console.log function you are referring to).

– Dale Burrell
Nov 21 '18 at 2:12















Inside the createFrom method I console.log the value and as mentioned it's undefined.

– jmckie
Nov 21 '18 at 2:15





Inside the createFrom method I console.log the value and as mentioned it's undefined.

– jmckie
Nov 21 '18 at 2:15




1




1





Can you please update your code... the code you have shown doesn't include passing the farmName in, and is missing the console.log you refer to. It makes it hard to help.

– Dale Burrell
Nov 21 '18 at 2:17





Can you please update your code... the code you have shown doesn't include passing the farmName in, and is missing the console.log you refer to. It makes it hard to help.

– Dale Burrell
Nov 21 '18 at 2:17













Thanks Dale I didn't realise I hadn't passed through the farmName!

– jmckie
Nov 21 '18 at 2:20





Thanks Dale I didn't realise I hadn't passed through the farmName!

– jmckie
Nov 21 '18 at 2:20












1 Answer
1






active

oldest

votes


















0














As Dale mentioned above, I didn't pass through the farmName.



openModal(millerIndex: number, farmIndex: number, view: number,
millerName: string, farmName: string) {
const modalRef = this.modalService.open(ModalComponent);
modalRef.componentInstance.millerIndex = millerIndex;
modalRef.componentInstance.farmIndex = farmIndex;
modalRef.componentInstance.view = view;
modalRef.componentInstance.millerName = millerName;
modalRef.componentInstance.farmName = farmName;

modalRef.result.then((result) => {
console.log(result);
}).catch((error) => {
console.log(error);
});
}





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',
    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
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53403931%2fangular-value-not-being-passed-to-modal-view%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









    0














    As Dale mentioned above, I didn't pass through the farmName.



    openModal(millerIndex: number, farmIndex: number, view: number,
    millerName: string, farmName: string) {
    const modalRef = this.modalService.open(ModalComponent);
    modalRef.componentInstance.millerIndex = millerIndex;
    modalRef.componentInstance.farmIndex = farmIndex;
    modalRef.componentInstance.view = view;
    modalRef.componentInstance.millerName = millerName;
    modalRef.componentInstance.farmName = farmName;

    modalRef.result.then((result) => {
    console.log(result);
    }).catch((error) => {
    console.log(error);
    });
    }





    share|improve this answer




























      0














      As Dale mentioned above, I didn't pass through the farmName.



      openModal(millerIndex: number, farmIndex: number, view: number,
      millerName: string, farmName: string) {
      const modalRef = this.modalService.open(ModalComponent);
      modalRef.componentInstance.millerIndex = millerIndex;
      modalRef.componentInstance.farmIndex = farmIndex;
      modalRef.componentInstance.view = view;
      modalRef.componentInstance.millerName = millerName;
      modalRef.componentInstance.farmName = farmName;

      modalRef.result.then((result) => {
      console.log(result);
      }).catch((error) => {
      console.log(error);
      });
      }





      share|improve this answer


























        0












        0








        0







        As Dale mentioned above, I didn't pass through the farmName.



        openModal(millerIndex: number, farmIndex: number, view: number,
        millerName: string, farmName: string) {
        const modalRef = this.modalService.open(ModalComponent);
        modalRef.componentInstance.millerIndex = millerIndex;
        modalRef.componentInstance.farmIndex = farmIndex;
        modalRef.componentInstance.view = view;
        modalRef.componentInstance.millerName = millerName;
        modalRef.componentInstance.farmName = farmName;

        modalRef.result.then((result) => {
        console.log(result);
        }).catch((error) => {
        console.log(error);
        });
        }





        share|improve this answer













        As Dale mentioned above, I didn't pass through the farmName.



        openModal(millerIndex: number, farmIndex: number, view: number,
        millerName: string, farmName: string) {
        const modalRef = this.modalService.open(ModalComponent);
        modalRef.componentInstance.millerIndex = millerIndex;
        modalRef.componentInstance.farmIndex = farmIndex;
        modalRef.componentInstance.view = view;
        modalRef.componentInstance.millerName = millerName;
        modalRef.componentInstance.farmName = farmName;

        modalRef.result.then((result) => {
        console.log(result);
        }).catch((error) => {
        console.log(error);
        });
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 '18 at 2:22









        jmckiejmckie

        1069




        1069
































            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53403931%2fangular-value-not-being-passed-to-modal-view%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

            Guess what letter conforming each word

            Port of Spain

            Run scheduled task as local user group (not BUILTIN)