我正在从其样式文件中对角度组件进行样式设置,发现必须使用:host,:host()或:host-context选择器,它们之间有什么区别?
在某些情况下,我想在 Angular 中加载页面时向下滚动到某个部分。
请注意:我想向下滚动而不单击任何内容(即ngOnInit)。
我尝试了这个:在我的component.html文件中
<div #sectionSubscribe>
HTML...
</div>
Run Code Online (Sandbox Code Playgroud)
在我的 component.ts 文件中
ngOnInit(){
this.scrollToSubscribe(sectionSubscribe);
}
scrollToSubscribe($element){
$element.scrollIntoView({
behavior: 'smooth',
block: 'start',
inline: 'nearest'
});
}
Run Code Online (Sandbox Code Playgroud)
但它不允许我这样做。请帮忙
我在使用 PrimeNG 日历组件时发现以下问题。
在我的 Angular 组件的 HTML 视图中,我定义了这个 PrimeNG 组件标签:
<p-calendar [disabled]="disabled"
[(ngModel)]="orderDetail.dettaglio_ordine.data_inserimento"
dateFormat="yyyy-mm-dd"></p-calendar>
Run Code Online (Sandbox Code Playgroud)
这应该查看包含在由orderDetail.dettaglio_ordine.data_inserimento标识的 JSON 对象字段中的日期。该字段包含以下值:2020-08-08”
事实上,在我的 JSON 中我有:
"data_inserimento": "2020-08-08",
Run Code Online (Sandbox Code Playgroud)
问题是,以这种方式执行此日期不会显示在空的渲染表单中。
为什么?怎么了?我缺少什么?我该如何解决这个问题?
从ASP.NET Core中删除此类项目后,Visual Studio 2017是否仍支持创建和编辑ASP.NET WebForms项目?
我用来DocumentsService从服务器获取图像文件,然后我用来 URL.createObjectURL(result)从服务器响应创建图像 url,一切似乎都正常,但我一直收到错误消息sanitizing unsafe URL并且看不到图像。
@Injectable()
export class DocumentsService {
public url:string = 'api.server.url'
constructor(private http: HttpClient , private dom: DomSanitizer) {
}
public getImageUrl(imageId: string): Observable<any> {
let requestOptions = {
params: {
id: imageId
},
responseType: "blob"
};
return this._restClientService.get(this.url, requestOptions).map(result => {
let url = URL.createObjectURL(result);
return this.dom.bypassSecurityTrustUrl(url);
});
}
}
Run Code Online (Sandbox Code Playgroud)
在我的组件中,我注入了服务并
this._doc.getImageUrl(doc.id)
.do(console.log) // => SafeUrlImpl {changingThisBreaksApplicationSecurity: "blob:http://localhost:4200/2b9b4820-c7d0-4920-a094-cb3e4cc47c7c"}
.subscribe(url => this.photoUrl = url)
}
Run Code Online (Sandbox Code Playgroud)
在模板中我使用一个函数来检查使用是否有图像
public getImagePath(): string {
if (this.photoUrl) …Run Code Online (Sandbox Code Playgroud) 我收到此错误消息
指定的值“2019-04-13T00:00:00”不符合要求的格式“yyyy-MM-dd”。
我想将日期/时间更改为日期。
日期时间示例:2019-04-13T00:00:00
我想做的例子:2019-04-13
HTML
<input
class="form-control mr-sm-2"
id="dates"
name="achievement_date"
[(ngModel)]="addItems.achievement_date"
required
type="date"
placeholder="Tournament Date"
/>
Run Code Online (Sandbox Code Playgroud) 我已经在我的 Windows 机器上全局安装了 Angular 7.2.0。路径是C:\Users\me\AppData\Roaming\npm\node_modules\@angular\cli,我需要运行像 Angular 6.0.0这样的旧项目。那么我是否需要在我的机器上安装这两个版本才能运行该项目?
当我们尝试使用 formGroup 时,我们会遇到一些错误。我需要一些关于表单组的解释。我想创建一个包含数据的表单组。数据需要逐行显示。 当我运行它时,我们使用 Angular 8 ,我收到此错误:
路径没有表单控件的值访问器:'rowDetails -> 0 -> no'
我有这个组件的构造函数:
constructor(
public fb: FormBuilder
) {
this.summaryForm = this.fb.group({
rowDetails: this.fb.array([])
})
}
Run Code Online (Sandbox Code Playgroud)
我有这个组件控制器:
ngOnInit() {
this.productList = (this.selectedReceiptBatch.incomeSummary as SaleSummary).sales;
this.summaryForm = this.fb.group({
rowDetails: this.fb.array(
this.productList.map(x=> this.fb.group({
'no': x.product.code,
'desc': x.product.productClass,
'numberx': [x.number.x],
'numbery': x.number.y,
'amountz': x.number.z,
'reference': [x.reference]
})
))
});
console.log(this.summaryForm);
this.formControlAvailable = true;
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<div *ngIf="formControlAvailable">
<div>
<div [formGroup]="summaryForm">
<div formArrayName="rowDetails">
<div *ngFor="let row of summaryForm.controls.rowDetails.controls; let index = index">
<div [formGroupName]="index"> …Run Code Online (Sandbox Code Playgroud) 我需要对元素进行切换操作:
<p-overlayPanel #panel>...
Run Code Online (Sandbox Code Playgroud)
我必须将其放入我的 .ts 代码中:
@ViewChild('panel') someInput: ElementRef;
this.someInput.toggle()
Run Code Online (Sandbox Code Playgroud)
之后我不知道我必须做什么?有人可以帮助我吗?
我在我的角度分量中有一个像这样定义的可观察量。
profiles$!: Observable<Profile[] | undefined>;`
Run Code Online (Sandbox Code Playgroud)
我尝试像这样检查模板中该数组的长度。
<div *ngIf="(profiles$ | async).length > 0"></div>
Run Code Online (Sandbox Code Playgroud)
Object is possibly 'null' or 'undefined'.通过这个构造,我从打字稿编译器得到了错误消息,这完全没问题。因此,向我的 if 条件添加一个空检查。
<div *ngIf="(profiles$ | async) && (profiles$ | async).length > 0"></div>
Run Code Online (Sandbox Code Playgroud)
我仍然收到相同的错误,该对象可能为空。我猜编译器无法识别空检查。我的问题是如何进行空检查以避免打字稿编译器出现错误。