app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'cwf',
templateUrl: './app.template.html'
})
export class AppComponent {
}
Run Code Online (Sandbox Code Playgroud)
并在app.template中有一些文字.如果在typescript文件中添加相同的文本作为模板,它可以工作.同样的事情,如果添加html然后调用html作为模板URL它不起作用.
我在父类中提交了按钮button in the parent component namely.
. 有很多人的课程.
每当我点击提交按钮时,我想在子类中调用一个方法.
如何使用从父到子的方法发出方法has many?
从孩子到父母很容易做到.我想访问子组件的html值,因此我需要从父到子发出一个事件.
我有personInvolved组件.该组件具有personDetails组件.personInvolved组件中有一个按钮.单击按钮我需要在DOM上附加personDetails.每次我点击它都应该附加personDetails组件.我怎样才能做到这一点.
我正在尝试将外部库应用于日期时间选择器.我收到如下错误
ERROR Error: Uncaught (in promise): Error: No value accessor for form control with name: 'dateTimeDeparture'
Error: No value accessor for form control with name: 'dateTimeDeparture'
Run Code Online (Sandbox Code Playgroud)
我的代码如下:
模板:
<owl-dateTime-input [(ngModel)]="flightDetails.dateTimeDeparture" name="dateTimeDeparture" [locale]="en" required></owl-dateTime-input>
Run Code Online (Sandbox Code Playgroud)
零件:
this.en = {
firstDayOfWeek: 0,
dayNames: ["Sunday", "Monday", "Tuesday","Wednesday", "Thursday", "Friday", "Saturday"],
dayNamesShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
monthNames: [ "January","February","March","April","May","June","July","August","September","October","November","December" ],
monthNamesShort: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun","Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
};
this.flightDetails = {
dateTimeDeparture: new Date(2017, 8, …Run Code Online (Sandbox Code Playgroud) datetimepicker angular angular-reactive-forms angular4-forms
在module.ts中
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { Router } from '@angular/router'
import { AppComponent } from './app.component';
@NgModule({
imports: [
BrowserModule
],
declarations: [
AppComponent
],
bootstrap: [ AppComponent ]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)
在组件中
import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { GlobalService } from './global.service';
@Component({
selector: 'cwf',
templateUrl: 'app/app.template.html'
})
export class AppComponent {
public homeConfig = {};
constructor(private _router:Router, private …Run Code Online (Sandbox Code Playgroud) 我有如下服务
return this._http
.post('/app/php/reports.php', data.toString(),
{headers: this.headers})
.toPromise()
.then(res => res.json().data)
.catch(this.handleError);
Run Code Online (Sandbox Code Playgroud)
我正在将我的代码从普通JS转换为angular.正常的ajax调用它工作正常.但我可以使用angular2发布帖子.有人可以建议我,为什么不打电话给.php
进口的东西是
import { Headers, Http, Response } from '@angular/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/toPromise';
Run Code Online (Sandbox Code Playgroud)
标题定义如下
private headers = new Headers({'Content-Type': 'application/json'});
Run Code Online (Sandbox Code Playgroud)
如果我在控制台错误中单击URL,则下载php文件.这意味着URL是正确的.
我可以在本地运行.仅在生产构建中获取错误.
我用过
import { CommonModule } from '@angular/common';
imports: [ CommonModule ]
Run Code Online (Sandbox Code Playgroud)
完整错误如下所示.
client:101 Template parse errors:enter code here`Can't bind to 'ngIf' since it isn't a known property of 'div'.
("move" class="transport-remove">Remove</a></div>
<div id="carTypeDiv_1" class="veh-inv-out" [ERROR ->]*ngIf="vehicleData.vesselType == 'road'">
<ul id="carTypeList_1" class="veh-slides">
"): VehicleDirective@10:52
Property binding ngIf not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "@NgModule.declarations". ("t:" (click)="removeField($event)" title="Remove" class="transport-remove">Remove</a></div>
[ERROR ->]<div id="carTypeDiv_1" …Run Code Online (Sandbox Code Playgroud)