如何在子组件观察到输入变化时调用父组件的功能?
以下是HTML结构.
# app.comopnent.html
<form>
<textbox>
<input type="text">
</textbox>
</form>
# textbox.component.html
<div class="textbox-wrapper">
<ng-content>
</div>
Run Code Online (Sandbox Code Playgroud)
限制如下.
ng-content并且需要将input元素投影到它.input元素输入时,在TextboxComponent中发出一个事件.input元素具有更多属性,例如<input type="text" (input)="event()">.我正在编写代码,但无法找到解决方案......
# input.directive.ts
@Directive({ selector: 'input', ... })
export class InputDirective {
ngOnChanges(): void {
// ngOnChanges() can observe only properties defined from @Input Decorator...
}
}
# textbox.component.ts
@Component({ selector: 'textbox', ... })
export class TextboxComponent {
@ContentChildren(InputDirective) inputs: QueryList<InputDirective>;
ngAfterContentInit(): void {
this.inputs.changes.subscribe((): void => { …Run Code Online (Sandbox Code Playgroud) 使用 CloudFormation 创建 EC2 实例,但根卷的名称(标签)为空。如何使用 CloudFormation 设置它?
# ec2-instance.yml (CloudFormation template)
MyInstance:
Type: "AWS::EC2::Instance"
Properties:
ImageId: "ami-da9e2cbc"
InstanceType: "t2.nano"
KeyName: !Ref "KeyPair"
Tags: # This is for EC2 instance (not root volume)
- Key: "Name"
Value: "my-instance"
Run Code Online (Sandbox Code Playgroud)
我找到了“Volumes”和“BlockDeviceMappings”属性,但它不能。
我正在使用Angular 2(RC.3)和@ angular/router alpha.8创建一个Web应用程序.这个新路由器提供"Guard",它帮助我们实现处理授权重定向.
正式文档写了如何创建和使用Guard,但其示例代码没有考虑连接时间. https://angular.io/docs/ts/latest/guide/router.html#!#can-activate-guard
所以我想在其中使用Observable(或Promise).
export class ApiService {
constructor(private _http: Http) {}
head(url: string): Observable<any> {
const req: any = { method: RequestMethod.Head, url: URI_SCHEME + url };
return this._http.request(new Request(req));
}
}
export class AuthGuard implements CanActivate {
constructor(private _api: ApiService) {}
canActivate(): Observable<boolean> {
return this._api.head('/users/self').subscribe(
(): Observable<boolean> => {
// when gets 200 response status...
return Observable.of(true);
},
(): Observable<boolean> => {
// when gets 401 error response...
// TODO: …Run Code Online (Sandbox Code Playgroud) 我创建以下CloudFormation模板文件来创建ECS群集和TaskDefinition,Service,但出现错误。这些设置有什么问题?
Please verify that the ECS service role being passed has the proper permissionsRole: !ImportValue "IAMRoleECSService",不会发生错误,但是不能从完成CREATE_IN_PROGRESSECSApplicationService:
Type: "AWS::ECS::Service"
DependsOn:
- "ECSApplicationCluster"
- "ECSApplicationTaskDefinition"
Properties:
Cluster: !Ref "ECSApplicationCluster"
DeploymentConfiguration:
MaximumPercent: 100
MinimumHealthyPercent: 50
DesiredCount: 4
LoadBalancers:
- ContainerName: !Ref "ContainerAppName"
ContainerPort: 80
TargetGroupArn: !ImportValue "ALBTargetGroup"
Role: !ImportValue "IAMRoleECSService"
ServiceName: "ecs-application-service"
TaskDefinition: !Ref "ECSApplicationTaskDefinition"
IAMRoleECSService:
Type: "AWS::IAM::Role"
Properties:
RoleName: "ecs-service"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- "ecs.amazonaws.com"
Action:
- "sts:AssumeRole"
Policies:
- …Run Code Online (Sandbox Code Playgroud) 如何使用Angular2中的Request类将自定义字段附加到HTTP Request标头?我找到了解决类似问题的帖子,但他们没有使用Request类.
我的代码如下.
let headers: Headers = new Headers();
headers.append('foo', 'bar');
let req: any = {
method : RequestMethod.Get,
url : '/test.json',
headers: headers,
};
// this.http is Http instance variable.
this.http.request(new Request(req)).map((res: any) => res.json());
Run Code Online (Sandbox Code Playgroud)
这是非常简单的代码.但是在执行此操作时,我无法使用Google Chrome的开发人员工具在HTTP请求标头中找到自定义字段.
参考:https://angular.io/docs/js/latest/api/http/index/Request-class.html
可以重现这个问题.下面的代码应该会出现XHR 400错误,但这不是问题.但请注意,请求标头没有自定义字段.
有没有办法将ngForm用于某些元素(不是form元素)?
// ERROR
<div #sampleForm="ngForm">
...
</div>
Run Code Online (Sandbox Code Playgroud)
我听说form元素有一个ngForm应用实例,它提供了一些功能.但我想知道如何在某些元素中获取ngForm的实例.