0

I am new to angularJS2.It might be a dummy question for you I searched many forums and failed about getting input value to json value in typeScript. You know how I should write my submit() function to get input values from screen and console it to screen when I click submit button? You can find the codes below. Please let me know if you have inquiries .

Regards

   <!DOCTYPE html> 
    <html>
   <form name="myForm" ng-submit="submit()">
       <head>
        <link rel="stylesheet" href="guiTransformatorStyles.css">
      </head>
    <body>
    <table>
     <br>
       <ul class="nav nav-pills nav-stacked">
      <tr><td>   <input type="text" value="&nbsp;" ng-model="myForm.productName">                                                                                   </td></tr>
    </ul>
    </table>
   </body>
        </form>
     </html>

This is my typeScript file :

 import { Component, OnInit} from '@angular/core';
  import { Router } from '@angular/router';
 import { FormGroup, FormBuilder } from '@angular/forms';
 import { Http } from '@angular/http';


 @Component({
   moduleId: module.id,
  templateUrl: 'navigation.component.html',
   host: {'(window:keydown)' : 'hotkeys($event)'},

 })

export class NavigationComponent implements OnInit {

 form: FormGroup;

 ngOnInit(): void { }

 constructor(private router: Router) {

 }



 submit() {
   alert('submit');
 }


  }
2
  • 1
    ...ng-model and ng-submit are AngularJS syntax.... Commented Mar 16, 2017 at 8:51
  • 1
    plnkr Like this? Commented Mar 16, 2017 at 8:57

1 Answer 1

1

As @AJT_82 said. You are using AngularJS syntax in a Angular 2 project. Use [(ngModel)] and (submit) instead of ng-model and ng-submit.

(Not to mention that you are starting a form in the head of your html and using body / head in a template)

Sign up to request clarification or add additional context in comments.

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.