Angular 2 ngOnInit变量

时间:2018-01-04 13:04:11

标签: angular

我对angular2很新,而且我有点卡在某事上。

服务:

<Label Text="{Binding CardNumber, StringFormat={0:### ### ###}" TextColor="#1481BA" />

控制器:

/*
 * Verifies that a Proposal response is properly signed. The payload is the
 * concatenation of the response payload byte string and the endorsement The
 * certificate (public key) is gotten from the Endorsement.Endorser.IdBytes
 * field
 *
 * @param crypto the CryptoPrimitives instance to be used for signing and
 * verification
 *
 * @return true/false depending on result of signature verification
 */
public boolean verify(CryptoSuite crypto) {

    if (isVerified()) { // check if this proposalResponse was already verified   by client code
        return isVerified();
    }

    if (isInvalid()) {
        this.isVerified = false;
    }

    FabricProposalResponse.Endorsement endorsement = this.proposalResponse.getEndorsement();
    ByteString sig = endorsement.getSignature();

    try {
        Identities.SerializedIdentity endorser = Identities.SerializedIdentity
                .parseFrom(endorsement.getEndorser());
        ByteString plainText = proposalResponse.getPayload().concat(endorsement.getEndorser());

        if (config.extraLogLevel(10)) {

            if (null != diagnosticFileDumper) {
                StringBuilder sb = new StringBuilder(10000);
                sb.append("payload TransactionBuilderbytes in hex: " + DatatypeConverter.printHexBinary(proposalResponse.getPayload().toByteArray()));
                sb.append("\n");
                sb.append("endorser bytes in hex: "
                        + DatatypeConverter.printHexBinary(endorsement.getEndorser().toByteArray()));
                sb.append("\n");
                sb.append("plainText bytes in hex: " + DatatypeConverter.printHexBinary(plainText.toByteArray()));

                logger.trace("payload TransactionBuilderbytes:  " +
                        diagnosticFileDumper.createDiagnosticFile(sb.toString()));
            }

        }

        this.isVerified = crypto.verify(endorser.getIdBytes().toByteArray(), config.getSignatureAlgorithm(),
                sig.toByteArray(), plainText.toByteArray()
        );
    } catch (InvalidProtocolBufferException | CryptoException e) {
        logger.error("verify: Cannot retrieve peer identity from ProposalResponse. Error is: " + e.getMessage(), e);
        this.isVerified = false;
    }

    return this.isVerified;
} // verify

我需要在ngOnInit()之外的任何帮助!!!

3 个答案:

答案 0 :(得分:1)

您需要将值(data.id)分配给变量(id),就像这样。

document:any;
    id:any;
        ngOnInit() {
          this.documentTypeService.getType(id).subscribe(data => {
    document=data;
    this.id= data.id;
    console.log(this.id);
    });
    console.log(this.id); 
        }

答案 1 :(得分:1)

尝试按以下方式分配ID

this.id = data.id;

您现在可以在ng.nOt()之外的console.log中输入id,如下所示

console.log(this.id)

答案 2 :(得分:0)

您应该编写this.id来访问类字段。像这样:

document:any;
id:any;
ngOnInit() {
  this.documentTypeService.getType(id).subscribe(data => {
    this.document = data;
    this.id = data.id;
    console.log(this.id); 
  });
  console.log(this.id); 
}

第二个输入是undefined,这意味着当您调用this.idconsole.log仍然为空 - 它们正在同步执行并且您尝试访问尚不存在的数据。

了解async \ await。