账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    angular 编程时遇到的问题:为何html模板中{{stock.id}} undefined
    31
    0

    以下是html模板对应的ts代码
    import {Component, OnInit} from '@angular/core';
    import {ActivatedRoute, Params, Router} from "@angular/router";

    @Component({
    selector: 'app-others',
    templateUrl: './others.component.html',
    styleUrls: ['./others.component.css']
    })
    export class OthersComponent implements OnInit {

    // private info: number;
    private stock: Stock;
    private isPro: boolean;
    private focus: boolean = false;

    constructor(private routeinfo: ActivatedRoute) {

    }

    ngOnInit() {

    //routeinfo.snapshot是快照方法接收参数,只能在初始化的时候实现一次
    // this.info = this.routeinfo.snapshot.params["id"];
    //routeinfo.params.subscribe订阅方法是根据参数变化而进行参数传递
    this.routeinfo.params.subscribe((params: Params) => this.stock.id = params["id"]);
    this.isPro = this.routeinfo.snapshot.data[0]["isPro"];

    }

    isForce() {

    return this.focus;

    }
    }

    export class Stock {
    constructor(public id: number, public name: string) {

    }
    }

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 酷girl. 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部