employee.component.ts
import { Component, OnInit } from "#angular/core";
import { EmployeeService } from "../Shared/employee.service";
import { NgForm } from "#angular/forms";
#Component({
selector: "app-employe",
templateUrl: "./employe.component.html",
styleUrls: ["./employe.component.css"]
})
export class EmployeComponent implements OnInit {
constructor(private employeeService: EmployeeService) {}
ngOnInit() {
this.resetForm();
}
resetForm(form?: NgForm) {
if (form != null) form.reset();
this.employeeService.SelectedEmployee = {
EmpId: null,
FirstName: "",
LastName: "",
EmpCode: "",
Position: "",
Office: ""
};
}
onSubmit(form ?:NgForm){
this.employeeService.postEmployee(form.value).subscribe(data =>{
this.resetForm(form);
})
}
}
Employee.service.ts
import { Injectable } from "#angular/core";
import { Employee } from "./employee.model";
import {
Http,
Response,
Headers,
RequestOptions,
RequestMethod
} from "#angular/http";
import { Observable } from "rxjs/Observable";
import 'rxjs/add/operator/map';
import "rxjs/add/operator/toPromise";
import 'rxjs/add/operator/catch';
import { map } from 'rxjs/operators';
import 'rxjs/add/operator/map';
#Injectable({
providedIn: "root"
})
export class EmployeeService {
SelectedEmployee: Employee;
constructor(private http: Http) {}
postEmployee(emp : Employee){
var body = JSON.stringify(emp);
var headerOptions = new Headers({'Content-Type':'application/json'});
var requestOptions = new RequestOptions({method : RequestMethod.Post,headers : headerOptions});
return this.http.post('http://localhost:3184/api/Emp',body,requestOptions).map(x => x.json());
}
}
<form class="emp-form" #employeForm="ngForm" >
<input type="hidden" name="EmployeeID" #EmployeeID="ngModel" [(ngModel)]="employeeService.SelectedEmployee.EmpID">
<div class="form-row">
<div class="form-group col-md-6">
<input class="form-control" name="FirstName" #FirstName="ngModel" [(ngModel)]="employeeService.SelectedEmployee.FirstName"
placeholder="First Name" required>
<div class="validation-error" *ngIf="FirstName.invalid && FirstName.touched">This Field is Required.</div>
</div>
<div class="form-group col-md-6">
<input class="form-control" name="LastName" #LastName="ngModel" [(ngModel)]="employeeService.SelectedEmployee.LastName" placeholder="Last Name"
required>
<div class="validation-error" *ngIf="LastName.invalid && LastName.touched">This Field is Required.</div>
</div>
</div>
<div class="form-group">
<input class="form-control" name="Position" #Position="ngModel" [(ngModel)]="employeeService.SelectedEmployee.Position" placeholder="Position">
</div>
<div class="form-row">
<div class="form-group col-md-6">
<input class="form-control" name="EmpCode" #EmpCode="ngModel" [(ngModel)]="employeeService.SelectedEmployee.EmpCode" placeholder="Emp Code">
</div>
<div class="form-group col-md-6">
<input class="form-control" name="Office" #Office="ngModel" [(ngModel)]="employeeService.SelectedEmployee.Office" placeholder="Office">
</div>
</div>
<div class="form-row">
<div class="form-group col-md-8">
<button [disabled]="!employeForm.valid" type="submit" class="btn btn-lg btn-block btn-info" (click)="onSubmit(employeForm)">
<i class="fa fa-floppy-o"></i> Submit</button>
</div>
<div class="form-group col-md-4">
<button type="button" class="btn btn-lg btn-block btn-secondary" (click)="resetForm(employeForm)">
<i class="fa fa-repeat"></i> Reset</button>
</div>
</div>
</form>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
using System.Web.Http.Cors;
namespace WebDemo
{
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
config.EnableCors(new EnableCorsAttribute("http://localhost:4200", headers: "*", methods: "*"));
// methods:'Access-Control-Request-Method',
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
}
Here I tried to use Post Data on SqlServer on Button Press and it gives me this error:
Failed to load resource: the server responded with a status of 400 (Bad Request)
localhost/:1 Access to XMLHttpRequest at 'http://localhost:3184/api/Emp' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Please help me to resolve, thanks in advance. I used the reference enter link description here
add origin option before url you need to allow:
config.EnableCors(new EnableCorsAttribute(origins: "http://localhost:4200", headers: "*", methods: "*"));
also you can allow every url like this
config.EnableCors(new EnableCorsAttribute(origins: "*", headers: "*", methods: "*"));
try this
var cors = new EnableCorsAttribute("*", "*", "*");
config.EnableCors(cors);
400 Error is clear indication of wrong data passing to server. Please check the data what server is expecting and the data you are passing from the Angular side.
Related
I am getting the data from the database using an Api which is in the LeaveService. To get the data the method used is applyLeaveGet(id:string) which is in LeaveService. This method provides certain values like the joiningDate from the database.
I am using Angular Material UI with reactive form.
The issue is that even though the leave instance is getting the data, but the in ngOnInt(), the properties are not getting the values.ngOnInt() does get triggred. For example I get the error undefined for joining date.
How can I solve the issue. Thank you for the help
LeaveService : applyLeaveGet(id:string) method
applyLeaveGet(id:string){
return this.http.get<Leave>('https://localhost:44330/api/leave/ApplyLeaveGet/'+ id);
}
ApplyLeave Component
import { HttpClient } from '#angular/common/http';
import { Component, OnInit } from '#angular/core';
import { FormBuilder, FormControl, FormGroup} from '#angular/forms';
import { ActivatedRoute } from '#angular/router';
import { AuthenticationService } from 'src/app/authentication.service';
import { Leave } from '../interfaces/leave';
import { LeaveService } from '../services/leave.service';
#Component({
selector: 'app-add-edit-leave',
templateUrl: './add-edit-leave.component.html',
styleUrls: ['./add-edit-leave.component.css']
})
export class AddEditLeaveComponent implements OnInit {
form: FormGroup;
currentDate = new Date();
minDate: Date;
maxDate: Date;
selectedFile: File = null;
url : any;
leave :Leave;
constructor(private fb: FormBuilder, private http: HttpClient
,private leaveService : LeaveService
,private route : ActivatedRoute
,private authenticationService: AuthenticationService
) {
leaveService.applyLeaveGet(authenticationService.getUserId())
.subscribe(data =>
this.leave = data
);
// Set the minimum to January 1st 20 years in the past and December 31st a year in the future.
const currentYear = new Date().getFullYear();
this.minDate = new Date(currentYear - 20, 0, 1);
this.maxDate = new Date(currentYear + 1, 11, 31);
}
ngOnInit() {
this.form = this.fb.group({
"currentDate": new FormControl(this.currentDate.toISOString().split("T")[0]),
"joiningDate":[''],
"fromDate":[''],
"tillDate":[''],
"leaveType":[''],
"duration":[''],
"reason":[''],
"filePath":['']
});
}
onSelectFile(event: any) {
this.selectedFile = <File>event.target.files[0];
if (event.target.files && event.target.files[0]) {
var reader = new FileReader();
reader.onload = (event: any) => {
this.url = event.target.result;
}
reader.readAsDataURL(event.target.files[0]);
}
else
{
this.url = "";
}
}
onSubmit(){
var userId = this.authenticationService.getUserId();
const formData = new FormData();
formData.append('userId', userId);
formData.append('currentDate', this.form.value.fullName);
formData.append('joiningDate', this.form.value.fullName);
formData.append('fromDate', this.form.value.fullName);
formData.append('tillDate', this.form.value.fullName);
formData.append('leaveType', this.form.value.fullName);
formData.append('duration', this.form.value.fullName);
formData.append('reason', this.form.value.fullName);
formData.append('balanceAnnualLeave', this.form.value.fullName);
formData.append('balanceSickLeave', this.form.value.fullName);
formData.append('balanceAnnualLeave', this.form.value.fullName);
formData.append('File', this.selectedFile);
}
}
this is the html
<p>add-edit-leave works!</p>
<div class="container">
<form class="form-container" [formGroup]="form" (ngSubmit)="onSubmit()">
<mat-card>
<mat-card-header>
<mat-card-title>Apply Leave</mat-card-title>
</mat-card-header>
<mat-card-content>
<div class="row">
<div class="col-md-6">
<mat-form-field class="full-width">
<mat-label>Today's Date</mat-label>
<input formControlName="currentDate" type="date" class="form-control" matInput placeholder="Today's Date" readonly >
</mat-form-field>
</div>
<div class="col-md-6">
<mat-form-field class="full-width">
<mat-label>Joining Date</mat-label>
<input formControlName="joiningDate" type="datetime" class="form-control" matInput placeholder="Joining Date">
</mat-form-field>
</div>
</div>
<!--Date Requested For-->
<div class="row">
<div class="col-md-6">
<mat-form-field class="full-width" appearance="fill">
<mat-label>From Date</mat-label>
<input matInput formControlName="fromDate" [min]="minDate" [max]="maxDate"
[matDatepicker]="picker">
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker></mat-datepicker>
</mat-form-field>
</div>
<div class="col-md-6">
<mat-form-field class="full-width" appearance="fill">
<mat-label>Till Date</mat-label>
<input matInput formControlName="tillDate" [min]="minDate" [max]="maxDate"
[matDatepicker]="pickerTillDate">
<mat-datepicker-toggle matSuffix [for]="pickerTillDate"></mat-datepicker-toggle>
<mat-datepicker #pickerTillDate></mat-datepicker>
</mat-form-field>
</div>
</div>
<!--Leave Type Duration(dropdown box)-->
<div class="row">
<div class="col-md-6">
<mat-form-field class="full-width" appearance="fill">
<mat-label>Leave Type</mat-label>
<select formControlName="leaveType" matNativeControl id="mySelectId">
<option value="" disabled selected></option>
<option value="Annual Leave">Annual Leave</option>
<option value="Sick Leave">Sick Leave</option>
</select>
</mat-form-field>
</div>
<div class="col-md-6">
<mat-form-field class="full-width" appearance="fill">
<mat-label>Duration</mat-label>
<select formControlName="duration" matNativeControl id="mySelectId">
<option value="" disabled selected></option>
<option value="Full Day ">Full Day</option>
<option value="First Half Day">First Half Day</option>
<option value="Second Half Day">Second Half Day</option>
</select>
</mat-form-field>
</div>
</div>
<!--Reason-->
<div class="row">
<div class="col-md-12">
<mat-form-field class="full-width">
<mat-label>Reason</mat-label>
<input formControlName="reason" matInput placeholder="Reason">
</mat-form-field>
</div>
</div>
<div class="row">
<div class="col-md-6">
<mat-label>Leave Balacne</mat-label><br>
<ul>
<li>
annualLeaveBalacne: <span>{{leave.balanceAnnualLeave}}</span> <br>
</li>
<li>
sickLeaveBalance: <span>{{leave.balanceSickLeave}}</span>
</li>
</ul>
</div>
</div>
<!--Submit-->
<mat-card-actions>
<button mat-stroked-button type="submit>Basic</button>
</mat-card-actions>
</mat-card-content>
</mat-card>
</form>
</div>
In the current version of your question it does not look like you are any setting values from this.leave in the form in OnInit. From your problem description and the rest of your code I think your problem is the asynchronous call of LeaveService in the constructor. As it it asynchronous code it might not be finished before ngOnInit is called and executed, thus the error messages about undefined values. You have to wait untill the HTTP call is finished before accessing the data.
As you should not perform potentially long running HTTP calls in the constructor, I suggest moving that part in OnInit. Everything that's not long running and asynchronous can be performed in the constructor. Your code could be refactored like this:
constructor(private fb: FormBuilder,
private http: HttpClient,
private leaveService : LeaveService,
private route : ActivatedRoute,
private authenticationService: AuthenticationService
) {
// Set the minimum to January 1st 20 years in the past and December 31st a year in the future.
const currentYear = new Date().getFullYear();
this.minDate = new Date(currentYear - 20, 0, 1);
this.maxDate = new Date(currentYear + 1, 11, 31);
this.form = this.fb.group({
"currentDate": new FormControl(this.currentDate.toISOString().split("T")[0]),
"joiningDate": [''],
"fromDate": [''],
"tillDate": [''],
"leaveType": [''],
"duration": [''],
"reason": [''],
"filePath": ['']
});
}
ngOnInit() {
leaveService.applyLeaveGet(authenticationService.getUserId())
.subscribe(data =>
{
this.leave = data;
// now data is here and can be used to set initial form values, example:
this.form.get('leaveType').setValue(this.leave.Type);
}
);
}
I'm trying to create from using AngularDart 5, angular_forms 2. The API seems to be very different from angular_forms 1 and I cannot figure out how to create a FormGroup using FormBuilder and ControlGroup. Below is my code.
LoginComponent.dart
import 'dart:convert';
import 'package:angular/angular.dart';
import 'package:angular_forms/angular_forms.dart';
#Component(
selector: 'login-comp',
templateUrl: 'login_component.html',
styleUrls: ['login_component.css'],
directives: [formDirectives, coreDirectives])
class LoginComponent implements OnInit {
ControlGroup ctrlGrp;
LoginComponent() {
this._createForm();
}
void _createForm() {
final email = Control<String>('', Validators.required);
final password = Control<String>(
'', Validators.compose([Validators.required, Validators.minLength(8)]));
this.ctrlGrp =
FormBuilder.controlGroup({'email': email, 'password': password});
}
#override
void ngOnInit() {}
void submit() {}
}
login_component.html
<div class="container d-flex justify-content-center align-times-center">
<div class="form-wrapper text-center">
<h2 class="text-center">Login</h2>
<form novalidate #f="ngForm" (ngSubmit)="submit()">
<div ngControlGroup="ctrlGrp">
<div class="form-group">
<input type="email" ngControl="email" class="form-control" id="email-input"
placeholder="Enter Email" formControlName="email"/>
</div>
<div class="form-group">
<input type="password" ngControl="password" class="form-control" id="password-input"
placeholder="Enter Password" formControlName="password"/>
</div>
</div>
<button type="submit" class="btn btn-primary" [disabled]="!f.valid">Submit</button>
</form>
<small><a [routerLink]="'/signup'">Need an Account?</a></small>
</div>
</div>
pubspec.yaml
environment:
sdk: '>=2.0.0 <3.0.0'
dependencies:
angular: ^5.0.0
ng_bootstrap: ^1.1.1
sass_builder: ^2.0.0
angular_router: ^2.0.0-alpha+19
angular_forms: ^2.1.1
dev_dependencies:
angular_test: ^2.0.0
build_runner: ^1.0.0
build_test: ^0.10.2
build_web_compilers: ^0.4.0
test: ^1.0.0
How can I create a FormGroup with angular_forms 2?
How can I bind a from group to formGroup attribute in html template?
Thanks.
I was able to find the answer with the help of #ebelair.
I was missing the [ngFormModel]="loginForm" part.
Below is the working code.
login_component.dart
#Component(
selector: 'login-comp',
templateUrl: 'login_component.html',
styleUrls: ['login_component.css'],
directives: [formDirectives, coreDirectives, routerDirectives])
class LoginComponent implements OnInit {
ControlGroup loginForm;
LoginComponent() {
this._createForm();
}
void _createForm() {
final email = Control<String>('', Validators.required);
final password = Control<String>('', Validators.compose([Validators.required, Validators.minLength(8)]));
this.loginForm = FormBuilder.controlGroup({'email': email, 'password': password});
}
#override
void ngOnInit() {}
void submit() {
print(this.loginForm.value['email']);
print(this.loginForm.value['password']);
}
}
login_component.html
<div class="container d-flex justify-content-center align-times-center">
<div class="form-wrapper text-center">
<h2 class="text-center">Login</h2>
<form novalidate [ngFormModel]="loginForm" (ngSubmit)="submit()">
<div>
<div class="form-group">
<input type="email" ngControl="email" class="form-control" id="email-input"
placeholder="Enter Email" formControlName="email"/>
</div>
<div class="form-group">
<input type="password" ngControl="password" class="form-control" id="password-input"
placeholder="Enter Password" formControlName="password"/>
</div>
</div>
<button type="submit" class="btn btn-primary" [disabled]="!loginForm.valid">Submit</button>
</form>
<small><a [routerLink]="'/signup'">Need an Account?</a></small>
</div>
</div>
Hope this helps.
Add ngFormModel in you form tag:
<form novalidate #f="ngForm" (ngSubmit)="submit()" [ngFormModel]="ctrlGrp"></form>
I am using Anugular 7 and angular material. I am currently getting an error when trying to submit a form via
(ngsubmit)="changePassword(formData)"
The other ngSubmits on the page are working without issue on submit. Just wondering if anyone has had this issue/knows of a resolution.
home.component.html (snippet)
<ng-template #changePassword let-c="close" let-d="dismiss">
<div class="modal-header">
<h4 class="modal-title">Change Password</h4>
<button type="button" class="close" (click)="d('Cross Click')">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div *ngIf="msg" role="alert" class="alert alert-success alert-dismissible">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
<mat-icon>done</mat-icon>
<span class="sr-only">Error:</span>
{{modalMsg}}
</div>
<form novalidate (ngSubmit)="changePassword(changePasswordFrm)" [formGroup]="changePasswordFrm">
<div class="form-group">
<div>
<span>Email Address*</span>
<input type="text" class="form-control" value="{{emailAddress}}" readonly formControlName="EmailAddress" />
</div>
<div>
<span>Old Password*</span>
<input type="password" class="form-control" value="{{password}}" readonly formControlName="OldPassword" />
</div>
<div>
<span>New Password*</span>
<input type="password" class="form-control" placeholder="New Password" formControlName="NewPassword" />
</div>
<div>
<span>Confirm Password*</span>
<input type="password" class="form-control" placeholder="Confirm Password" formControlName="ConfirmPassword" />
</div>
</div>
<div class="modal-footer">
<button type="submit" [disabled]="changePasswordFrm.invalid" class="btn btn-primary">Change Password</button>
<button type="button" class="btn btn-outline-dark" (click)="c('Save click')">Cancel</button>
</div>
</form>
</div>
</ng-template>
home.component.ts
createChangePasswordFrm() {
this.changePasswordFrm = this.fb.group({
EmailAddress: "",
OldPassword: "",
NewPassword: ["", Validators.required],
ConfirmPassword: ["", Validators.required]
});
}
changePassword(formData: any): void {
this.loginService.changeUserPassword(formData).subscribe(
data => {
if (data.Successful) {
this.msg = data.Information;
this.createLoginFrm();
this.activeModal.close();
this.isLoading = false;
}
else {
this.modalMsg = data.Information;
}
},
error => this.modalMsg = error);
}
app.module.ts
import { BrowserModule } from '#angular/platform-browser';
import { NgModule } from '#angular/core';
import { CommonModule, APP_BASE_HREF } from "#angular/common";
import { MatFormFieldModule, MatSelectModule, MatDialogModule, MatTableModule } from "#angular/material";
import { MatIconModule} from "#angular/material/icon";
import { ReactiveFormsModule, FormsModule } from "#angular/forms";
import { HttpClientModule } from "#angular/common/http";
import { BrowserAnimationsModule } from "#angular/platform-browser/animations";
import { NgbModule } from "#ng-bootstrap/ng-bootstrap";
import { appRoutingModule } from "./app.routing";
import { AppComponent } from "./app.component";
import { HomeComponent } from "./component/home/home.component";
import { UsersComponent } from "./component/users/users.component";
import { AuthService } from "./service/auth.service";
import { LoginService } from "./service/login.service";
import { UserService } from "./service/user.service";
import { ResourceService } from "./service/resource.service";
#NgModule({
declarations: [
AppComponent,
HomeComponent,
UsersComponent
],
imports: [
BrowserModule,
MatIconModule,
MatFormFieldModule,
MatSelectModule,
MatDialogModule,
MatTableModule,
ReactiveFormsModule,
FormsModule,
CommonModule,
BrowserAnimationsModule,
HttpClientModule,
NgbModule.forRoot(),
appRoutingModule
],
providers: [{ provide: APP_BASE_HREF, useValue: '/' }, AuthService, LoginService, UserService, ResourceService],
bootstrap: [AppComponent]
})
export class AppModule { }
So for those that come across this issue. The normal reason for this is that your ng-template possibly shares a name with a method call.
As you can see from above the ng-template was called #changePassword. On submit it called the "method" changePassword(). This was causing angular to get confused as to whether it should call the method or the ng-template.
Changing the method name resolved the issue.
Here im trying to hit my Api from ang2 why its not hitting. Even my Fiddler also not caughing traffic please check my code
constructor(private fb: FormBuilder, private _http: Http) {
_http.get('http://localhost:40039/Api/Home/GetEmp').subscribe(result => {
this.ctstArrayList = result.json();
}
)}
doSubmit(): Observable<Customer> {
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this._http.post('http://localhost:40039/Api/Home/SaveEmp', JSON.stringify(this.custobj), options)
.map(this.extractData)
.catch(this.handleError);
}
This is my html code here i implement ngtoch and other some validation
Html code
<form class="form-horizontal" novalidate (ngSubmit)="doSubmit()" [formGroup]="customerForm">
<fieldset>
<div class="form-group" [ngClass]="{'has-error': (customerForm.get('EmpName').touched ||
customerForm.get('EmpName').dirty) &&
!customerForm.get('EmpName').valid }">
<label for="name">Name</label>
<input type="text" class="form-control" formControlName="EmpName" [(ngModel)]="custobj.EmpName" />
<span>Hell{{custobj.EmpName}}</span>
<span class="help-block" *ngIf="(customerForm.get('EmpName').touched ||
customerForm.get('EmpName').dirty) &&
customerForm.get('EmpName').errors">
<span *ngIf="customerForm.get('EmpName').errors.required">
Please enter your first name.
</span>
<span *ngIf="customerForm.get('EmpName').errors.minlength || customerForm.get('EmpName').errors.maxlength">
The first name must be longer than 3 and max6 characters.
</span>
</span>
</div>
<button type="submit" class="btn btn-success btn-block" (click)="doSubmit(custobj)" [disabled]="!(customerForm.valid)">Submit</button>
im quite new with angular2, but i seem to manage ok for a beginner. However, i'm stuck on some validation issues. i want to validate a component that is not a form field (e.g. input, select e.t.c).
I'm using a bootstrap dropdown which uses an unsorted list.
dropdownButtons.html
<div class="btn-group" dropdown>
<button type="button" class="btn btn-default" dropdownToggle >
{{ selected ? selected : 'Type...'}}
</button>
<ul class="dropdown-menu" dropdownMenu>
<li *ngFor="let value of values;let i = index" (click)="onChange(value)">
{{value.label}}
</li>
</ul>
</div>
dropdownButtons.component.ts
import {Component, EventEmitter, Output, Input, Injectable} from '#angular/core';
import { DROPDOWN_DIRECTIVES } from 'ng2-bootstrap/ng2-bootstrap';
#Component({
selector: 'dropdown-buttons',
template: require('./dropdownButtons.html'),
directives: [DROPDOWN_DIRECTIVES]
})
#Injectable()
export class DropdownButtons {
#Input()
values: DropdownValue[] = [{ "value": "RSS", "label": "RSS" },{ "value": "REST", "label": "REST" }];
#Input()
selected : string;
#Output()
select: EventEmitter<DropdownValue>;
constructor() {
this.select = new EventEmitter();
}
onChange(type) {
this.select.emit(type);
}
}
export class DropdownValue {
value:string;
label:string;
constructor(value:string,label:string) {
this.value = value;
this.label = label;
}
}
My form looks like this.
<form (ngSubmit)="onSubmit()" #refererform="ngForm">
<div class="form-group">
<label for="inputUrl">Url</label>
<input type="text" class="form-control" id="inputUrl" placeholder="Url" required
[(ngModel)]="model.url" name="url">
</div>
<div class="form-group">
<dropdown-buttons [(selected)]="model.type" (select)="onSelect($event)" ></dropdown-buttons>
</div>
<div class="form-group" ng-show="showDetails" *ngIf="isShown()">
<label for="header">Header</label>
<textarea placeholder="Default Input" class="form-control" id="header"
[(ngModel)]="model.header" name="header"></textarea>
</div>
<div class="form-group" ng-show="showDetails" *ngIf="isShown()">
<label for="payload">Payload</label>
<textarea placeholder="Default Input" class="form-control" id="payload"
[(ngModel)]="model.payload" name="payload"></textarea>
</div>
<button type="submit" class="btn btn-danger" >Submit</button>
</form>
I tried to use ngModel (using required in the tags) and the FormGroup option, where i define some formcontrols. It works fine with form controls, but i can't seem to figure out how i validate non form components, is it even possible?
thanks in advance.