我一直在阅读ngrx示例应用程序的代码并找到两个函数调用
createFeatureSelector<AuthState>('auth');
和
createSelector(selectAuthState,(state: AuthState) => state.status);
这是做什么的?
export const selectAuthState = createFeatureSelector<AuthState>('auth');
export const selectAuthStatusState = createSelector(
selectAuthState,
(state: AuthState) => state.status
);
Run Code Online (Sandbox Code Playgroud) 我按照david east 的教程制作了一个有角度的通用应用程序,并将其部署在firebase托管上。我尝试了此方法,它适用于普通路由,但是对于延迟加载的路由却不起作用。这是查看页面源的屏幕截图, 查看页面源
为什么在路由时这不起作用?有人可以告诉我如何配置服务器端渲染以进行延迟加载或共享有关它的任何链接吗?
firebase firebase-hosting server-side-rendering angular-universal
我需要使用Angular 4检查文件夹中是否存在图像.我有一个从服务器返回的图像名称列表.我需要的是检查资产文件夹中是否存在该图像.任何帮助或想法都会很棒.
我无法使用放在button标记内的路由器链接属性进行导航。这是我的代码,
<button mat-raised-button color="primary"><a routerLink="/message-inbox">Inbox</a></button>
<button mat-raised-button color="accent"><a routerLink="/sent">Sent</a></button>
<a routerLink="/message-compose"><button color="warn">Compose</button></a>
Run Code Online (Sandbox Code Playgroud) 尝试设置对象索引签名时,出现错误的重复数字索引签名。这是工作示例,请单击此处
export class HelloComponent implements OnInit {
//works
watched: { [id: number]: boolean } = {} ; //works
//doesnt work
watchedOne: { [id: number]: boolean,
[fid: number]: boolean } = {} ; // Doesn't Work
constructor() {}
watch(talk): void {
console.log('watch', talk.id);
this.watched[talk.id] = true;
this.watchedOne[talk.id] = true; // error
console.log('watch-obj', this.watched);
}
ngOnInit() {
this.watch({
id: 9,
fid: 4
});
}
}
Run Code Online (Sandbox Code Playgroud) 是否有任何ECMAScript 6/7相当于下划线的range
功能?
在下划线中:
_.range(startPage, endPage + 1);
Run Code Online (Sandbox Code Playgroud)
在ES2015中:
Array.from(Array(n), (_, i) => x + i)
Run Code Online (Sandbox Code Playgroud)
不确定ES2015版本的工作原理.我想知道javascript的ecmascript中的范围是如何工作的
我想指定复选框的值而不是true或false.我怎样才能实现这一目标?
<input formControlName="ota" value="OTA" type="checkbox">
Run Code Online (Sandbox Code Playgroud) 将值从父级传递给子级.子组件中接收的值是未定义的工作示例
这是我的app.component
import { Component, OnInit } from '@angular/core';
import {HttpClient} from '@angular/common/http';
interface ItemsResponse {
data: any[];
}
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent implements OnInit {
constructor(private http: HttpClient) {}
ngOnInit() {
this.getPosts();
console.log( this.name); // name is undefined
}
name;
results:Array<any> = []; // code changed
getPosts() {
this.http.get<ItemsResponse>('https://reqres.in/api/users?page=3').subscribe(res =>
this.name = res); // code changed
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的hello组件,其中数据被传递给子组件您可以看到在构造函数中未定义通过angular的@input装饰器从父组件传递到子组件的名称.
import { Component, Input } from '@angular/core';
@Component({
selector: 'hello', …
Run Code Online (Sandbox Code Playgroud) 我正在学习如何使用 angular 的新 http 客户端模块。当我尝试使用其余 api 时,我收到错误无法读取未定义的属性“数据”。这是我的 app.html,
<div style="text-align:center">
<h1>
Welcome to {{title}}!
</h1>
<button (click)="getPosts()">Get Posts</button>
<div *ngFor="let result of results.data">
{{ result | json }}
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这是我的 app.component.ts
import { Component, OnInit } from '@angular/core';
import {HttpClient} from '@angular/common/http';
interface ItemsResponse {
data: any[];
}
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
results: any;
// Inject HttpClient into your component or service.
constructor(private http: HttpClient) {}
title = 'School2College'; …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用angular的新httpclient从api获取数据,我得到错误属性在IMessage []类型上不存在。如何为以下响应编写接口,
{"data":{"Messages":[{"Id":28,"MessageContent":"test data tsn","FromUserId":"74df8f98-2925-4242-8d32-8b09f3691396","UserName":"365@test.com","ToUserId":"96b1c943-ade0-4026-b8ed-0f4a6231e586","ProductId":null,"ParentMessageId":null,"Subject":"Test Message by Dev Team","StyleNumber":null}],"Pagination":{"Page":1,"PageLength":20,"TotalRecords":20,"TotalPages":1},"MessageLimit":{"TotalMessageCount":5,"RemainingMessageCount":3}}}
Run Code Online (Sandbox Code Playgroud)
我在这里尝试过的
export interface IMessage {
data: {
Messages: Messages[];
};
}
interface Messages {
id: number;
messageContent: string;
fromUserId: string;
toUserId: string;
productId?: number;
parentMessageId?: number;
subject: string;
styleNumber?: string;
}
Run Code Online (Sandbox Code Playgroud)
我在stackblitz上的代码
// Here is the code
import { Component, Input, OnInit } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { IMessage } from './message.interface';
import { HttpClient, HttpResponse, HttpParams, HttpHeaders } from '@angular/common/http';
@Component({
selector: 'hello',
template: …
Run Code Online (Sandbox Code Playgroud) 这就是我验证密码、确认密码和电子邮件、确认电子邮件的方式。如您所见,我有一个函数 fieldMatcher,它被调用来检查电子邮件和密码验证。
// Works
createForm() {
this.formGroup = this._formBuilder.group({
firstName: '',
lastName: '',
email: '',
confirmEmail: '',
password: '',
confirmPassword: '',
}, {validator: this.fieldMatcher});
}
fieldMatcher(c: AbstractControl): { invalid: boolean } {
if (c.get('password').value !== c.get('confirm').value) {
return {invalid: true};
}
if (c.get('email').value !== c.get('confirmEmail').value) {
return {invalid: true};
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想将控件作为参数传递给 fieldMatcher 函数,以便我减少如下代码但不起作用,
// Do not Work
createForm() {
this.formGroup = this._formBuilder.group({
firstName: '',
lastName: '',
email: '',
confirmEmail: '',
password: '',
confirmPassword: '',
},{validator: this.fieldMatcher(value1, value2)});
} …
Run Code Online (Sandbox Code Playgroud) angular ×8
angular-cli ×5
arrays ×1
ecmascript-6 ×1
ecmascript-7 ×1
firebase ×1
javascript ×1
ngrx ×1
ngrx-store ×1
typescript ×1