我做错了什么?
import {bootstrap, Component} from 'angular2/angular2'
@Component({
selector: 'conf-talks',
template: `<div *ngFor="talk of talks">
{{talk.title}} by {{talk.speaker}}
<p>{{talk.description}}
</div>`
})
class ConfTalks {
talks = [ {title: 't1', speaker: 'Brian', description: 'talk 1'},
{title: 't2', speaker: 'Julie', description: 'talk 2'}];
}
@Component({
selector: 'my-app',
directives: [ConfTalks],
template: '<conf-talks></conf-talks>'
})
class App {}
bootstrap(App, [])
错误是
EXCEPTION: Template parse errors:
Can't bind to 'ngFor' since it isn't a known native property
("<div [ERROR ->]*ngFor="talk of talks">
答案 0 :(得分:506)
我在let
前面错过了talk
:
<div *ngFor="let talk of talks">
请注意,#...
使用let
来声明NgFor等结构指令中的局部变量是不推荐使用的。请改用<div *ngFor="#talk of talks">
。
<div *ngFor="let talk of talks">
现在变为#
原始答案:
我在talk
前面错过了<div *ngFor="#talk of talks">
:
#
很容易忘记you forgot that # again
。我希望Angular异常错误消息代之以:
public void signDetached(String inputFilePath, String outputFilePath, String signatureImagePath, Sign signProperties) {
OutputStream outputStream = null;
InputStream inputStream = null;
PDDocument document = null;
InputStream signImageStream = null;
try {
setTsaClient(null);
document = PDDocument.load(inputFilePath);
// create signature dictionary
PDSignature signature = new PDSignature();
signature.setFilter(PDSignature.FILTER_ADOBE_PPKLITE);
signature.setSubFilter(PDSignature.SUBFILTER_ADBE_PKCS7_DETACHED);
signature.setName("VANDUC1102");
signature.setLocation(null);
String displayName = "Hello World, Document signed by VANDUC1102";
String reason = reasonText+ " " + displayName;
signature.setReason(reason);
// the signing date, needed for valid signature
signature.setSignDate(Calendar.getInstance());
int signatureInPage = signProperties.getPageNumber() + 1;
signImageStream = new FileInputStream(new File(signatureImagePath));
PDVisibleSignDesigner visibleSig = new PDVisibleSignDesigner(inputFilePath, signImageStream, signatureInPage);
float xAxis = convertPixel2Point(signProperties.getX()) ;
float yAxis = convertPixel2Point(signProperties.getY());
float signImageHeight = convertPixel2Point(signImageHeight);
float signImageWidth = convertPixel2Point(signImageWidth);
visibleSig.xAxis(xAxis)
.yAxis(yAxis)
.zoom(0)
.signatureFieldName("Signature")
.height(signImageHeight)
.width(signImageWidth);
PDVisibleSigProperties signatureProperties = new PDVisibleSigProperties();
signatureProperties.signerName(eiUser.getName())
.signerLocation(null)
.signatureReason(reason)
.preferredSize(0)
.page(signProperties.getPageNumber())
.visualSignEnabled(true)
.setPdVisibleSignature(visibleSig)
.buildSignature();
// register signature dictionary and sign interface
SignatureOptions signatureOptions = new SignatureOptions();
signatureOptions.setVisualSignature(signatureProperties);
signatureOptions.setPage(signatureInPage);
document.addSignature(signature, this, signatureOptions);
File outputFile = new File(outputFilePath);
outputStream = new FileOutputStream(outputFile);
inputStream = new FileInputStream(inputFilePath);
IOUtils.copyStream(inputStream, outputStream);
document.saveIncremental(inputStream, outputStream);
outputStream.flush();
} catch (COSVisitorException | SignatureException | IOException ex) {
log.error("signDetached ", ex);
} finally {
IOUtils.closeStream(outputStream);
IOUtils.closeStream(inputStream);
IOUtils.closeStream(signImageStream);
IOUtils.closeStream(document);
}
}
private float convertPixel2Point(float pixel){
return pixel * (float) 72/96;
}
。
答案 1 :(得分:51)
导致OP错误的另一个错误可能是使用in
:
<div *ngFor="let talk in talks">
您应该使用of
代替:
<div *ngFor="let talk of talks">
答案 2 :(得分:17)
This Statement used in Angular2 Beta version.....
Hereafter use let instead of #
let keyword is used to declare local variable
答案 3 :(得分:8)
就我而言,这是一封小写字母f
。
我正在分享这个答案,因为这是谷歌的第一个结果
请务必撰写 *ngFor
答案 4 :(得分:3)
答案 5 :(得分:3)
对我来说,长话短说,我无意中降级为角度-β-16。
let ...语法仅在2.0.0-beta.17 +
中有效如果您对此版本以下的任何内容尝试let语法。您将生成此错误。
升级到angular-beta-17或使用#item in items语法。
答案 6 :(得分:3)
仅在我遇到相同错误并且原因是在迭代器中使用而不是而不是 of 时,才涉及另一种情况
错误的方法let file in files
正确的方法let file of files
答案 7 :(得分:2)
在angular 7中,通过将以下行添加到.module.ts
文件中来解决此问题:
import { CommonModule } from '@angular/common';
imports: [CommonModule]
答案 8 :(得分:2)
您应该使用let关键字作为声明局部变量 例如* ngFor =“让我们谈论话题”
答案 9 :(得分:1)
使用此
<div *ngFor="let talk of talks>
{{talk.title}}
{{talk.speaker}}
<p>{{talk.description}}
</div>
您需要指定变量以遍历对象数组
答案 10 :(得分:1)
在我的例子中,= 和 " 之间不应该有空格,例如错误的 *ngFor = "let talk of talk" 右:*ngFor="让我们谈谈"
答案 11 :(得分:0)
我忘了用“ @Input”(注!)为组件添加注释。
book-list.component.html (违规代码):
<app-book-item
*ngFor="let book of book$ | async"
[book]="book"> <-- Can't bind to 'book' since it isn't a known property of 'app-book-item'
</app-book-item>
book-item.component.ts 的正确版本:
import { Component, OnInit, Input } from '@angular/core';
import { Book } from '../model/book';
import { BookService } from '../services/book.service';
@Component({
selector: 'app-book-item',
templateUrl: './book-item.component.html',
styleUrls: ['./book-item.component.css']
})
export class BookItemComponent implements OnInit {
@Input()
public book: Book;
constructor(private bookService: BookService) { }
ngOnInit() {}
}
答案 12 :(得分:0)
也不要在这种情况下尝试使用纯TypeScript ...我想更符合for
的用法,并使用*ngFor="const filter of filters"
并得到ngFor未知属性错误。只是用let代替const即可。
正如@ alexander-abakumov所说,of
被in
取代。
答案 13 :(得分:0)
就我而言,使用* ngFor包含组件的模块导致此错误,未包含在app.module.ts中。将其包含在imports数组中对我来说解决了这个问题。