0

I have html form (code given below). i am using angular 4. On clicking button its not calling typescript method present in "admin-form.component.ts" (code given below). Even it is not writing into console. Please help

Html Code : Filename- admin.html

<form>
     <div class="form-group row">
      <label for="fromDate" class="col-sm-2 form-col-label">From Date</label>
      <div class="col-sm-6"> 
      <input class="form-control" type="date" id="FromDate" name="fromdate"/>
      </div>
     </div>    
    <div class="form-group row">
       <button class="btn btn-primary col-sm-2" id="Save" type="submit" ng-click="insertSession()">Save</button>
     </div>
 </form>

Tyscript Code: File name-admin-form.component.ts

insertSession(){
  console.log('insertSession');
    this.dataService 
    .insertNewSession(this.newSession)
    .subscribe(
      data =>
      {
        this.newSession._id =data._id;
        this.sessions.push(this.newSession);
        this.newSession = SessionDetails.CreateDefault();

        console.log("Added user");

      }
    )
}
1
  • 2
    you might want to read docs on angular.io Commented Jan 8, 2018 at 6:31

2 Answers 2

1

ng-click is AngularJs syntax and (click) for Angular syntax.

You need to replace following code :

(click)="insertSession()"

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

Comments

0

ng-click is AngularJs syntax. you have to use click event in Angular 2

(click)="insertSession()"

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.