角度2到角度5升级---&gt;使用implements <lifecycle event =“”>

时间:2018-01-25 22:38:56

标签: javascript jquery angular angular2-routing angular5

  • 我正从角度2升级到角度5。
  • 在升级之前,他们让我做了这个步骤,他们在这个站点中从角度到2到角4 https://angular-update-guide.firebaseapp.com/
  • 不确定如何从OnInit更改为implements&lt;生命周期事件&gt;。
  • 提供我的代码段及以下内容。

确保您不使用扩展OnInit,或对任何生命周期事件使用扩展。而是使用工具。

https://angular-update-guide.firebaseapp.com/

<!-- language-all: lang-or-tag-here -->


import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import { Router } from '@angular/router';
import { SPORTSService } from '../../services/SPORTS.service';

declare var $: any;
@Component({
    selector: 'Player',
    templateUrl: "./Player.html"
})

export class Player implements OnInit {
    public userId;
    public staticSecurityList = [{ "name": "User", "id": "/Player/PlayerUser" },
    { "name": "Functional Roles", "id": "/Player/PlayerFunctionalRoles" },
    { "name": "Departmental Role Mapping", "id": "/Player/PlayerDepartmentRoleMapping" },
    { "name": "Aspects", "id": "/Player/PlayerAspects" },
    { "name": "Functional Role Mapping", "id": "/Player/PlayerFunctionalRolesMap" }];

    public staticMobilesList = [{ "name": "Delete Mobile", "id": "/Player/PlayerDeleteMobile" },
    { "name": "Non episodic show name", "id": "/Player/PlayerNonEpisodicShowName" },
    { "name": "Mobile Owner", "id": "/Player/PlayerMobileOwner" },
    { "name": "TVEverywhere", "id": "/Player/PlayerTVEverywhere" }];


    public staticGeneralPlayerList = [{ "name": "Unlock", "id": "/Player/PlayerUnlock" },
    { "name": "GWS Map Tagging", "id": "/Player/GwsMapTagging" }];

    public staticContractList = [{ "name": "Delete Contract", "id": "/Player/PlayerDeleteContract" }];

    public staticSchedulingList = [
        { "name": "Format", "id": "/Player/PlayerFormat" },
        { "name": "off the clock settings", "id": "/Player/PlayerOffTheClockSettings" },
        { "name": "Special Events", "id": "/Player/PlayerSpecialEvents" },
        { "name": "Event Template", "id": "/Player/PlayerEventTemplate" }];
    public schedulingList = [];
    public generalPlayerList = [];
    public securityList = [];
    public MobileList = [];
    public contractList = [];
    //public routeMethod;
    //public params;
    constructor(public router: Router, private SPORTSservice: SPORTSService) {
    }

    ngOnInit(): void {
        let attributes = this.SPORTSservice.getSeesionStorageValue();
        if (attributes) {
            this.userId = attributes.user_attributes.SSO[0];
        }
        //console.log(this.userId);
        let dateTime = this.SPORTSservice.todayDateWithTime();
        let saveUserTrackData = { "userId": this.userId, "screenId": 55, "actionId": 9, "comment": "Player" };
        this.SPORTSservice.getResponse('users/v1/saveusertrack', 'post', saveUserTrackData)
            .subscribe(
            data => {
            },
            err => { }
            );
        this.loadView();
    }


    loadView(): void {
        let that = this;
        that.privilegeSettings();
        $('.triggerLeftSlider').trigger('click');
        /* setTimeout( function() {
        $(".PlayerSubTabList li").click(function(){
            that.sliderReset(this);
        });
        let basePath = window.location.pathname;
        $('li[id="' + basePath + '"]').addClass('active');  
        }, 500); */

        $("#setKgridMinHeight").click(function () {
            that.setGridHeight();
        });
    }

    Player(event): void {
        let target = event.target || event.srcElement || event.currentTarget;
        let idAttr = target.attributes.id;
        let value = idAttr.nodeValue;
        //console.log(value);
        this.routeMethod(value);
        ////console.log('current route name', this.router.url);

        /* this.router.events.subscribe(event => {
if (event.constructor.name === 'NavigationStart') {
//console.log(event.url);
}
else
{
//console.log("dasdas");
}
});*/
    }


    sliderReset(x: any): void {


        //$('.leftSlider').addClass('toggleShow');
        //$('.slideShrinkBox').removeClass('active');
        //$('.leftSlider').removeClass('shoHideMenuActive');
        $(".PlayerSubTabList li").removeClass('active');
        setTimeout(function () {
            //$(x).addClass('active');  
            //$("#"+that.router.url).addClass("active");
        });
    }
    routeMethod(rotingName) {
        //console.log(rotingName);
        let that = this;
        that.router.navigate([rotingName]);
    }

    privilegeSettings(): void {
        //console.log(this.staticSecurityList.length)
        for (let i = 0; i < this.staticSecurityList.length; i++) {
            let userPrivilege = this.SPORTSservice.getUserPrivilege({ "parent": "Player", "child": this.staticSecurityList[i].name })
            if (userPrivilege) {
                this.securityList.push(this.staticSecurityList[i]);
            }
            ////console.log(userPrivilege+" "+i);
        }

        for (let i = 0; i < this.staticMobilesList.length; i++) {
            let userPrivilege = this.SPORTSservice.getUserPrivilege({ "parent": "Player", "child": this.staticMobilesList[i].name })
            if (userPrivilege) {
                this.MobileList.push(this.staticMobilesList[i]);
            }
            ////console.log(userPrivilege+" "+i);
        }
        for (let i = 0; i < this.staticGeneralPlayerList.length; i++) {
            let userPrivilege = this.SPORTSservice.getUserPrivilege({ "parent": "Player", "child": this.staticGeneralPlayerList[i].name })
            if (userPrivilege) {
                this.generalPlayerList.push(this.staticGeneralPlayerList[i]);
            }

        }

        for (let i = 0; i < this.staticContractList.length; i++) {
            let userPrivilege = this.SPORTSservice.getUserPrivilege({ "parent": "Player", "child": this.staticContractList[i].name })
            if (userPrivilege) {
                this.contractList.push(this.staticContractList[i]);
            }
        }

        for (let i = 0; i < this.staticSchedulingList.length; i++) {
            let userPrivilege = this.SPORTSservice.getUserPrivilege({ "parent": "Player", "child": this.staticSchedulingList[i].name })
            if (userPrivilege) {
                this.schedulingList.push(this.staticSchedulingList[i]);
            }
        }
    }
    setGridHeight() {
        let windowHeight = $(window).outerHeight();
        let navHeight = $('.navHeaderBox').outerHeight();
        let breadCrumbHeight = $('.breadCrumbBox').outerHeight();
        let gridActionsHeight = $('.gridCompBox').eq(0).outerHeight();
        let footerHeight = 38;
        let searchFormHeight = $('.formInputsBox').eq(0).outerHeight();
        let groupingHeaderHeight = $('.fixedKgrid .k-grouping-header').outerHeight();
        let headerHeight = $('.fixedKgrid .k-grid-header').outerHeight();
        let gridContentHeight = windowHeight - (navHeight + breadCrumbHeight + gridActionsHeight + footerHeight + searchFormHeight + groupingHeaderHeight + headerHeight + 20);
        $('.k-grid.fixedKgrid > .k-grid-content').css({ "min-height": gridContentHeight + "px" });
        $('.k-grid.fixedKgrid > .k-grid-content-locked').css({ "min-height": gridContentHeight + "px" });
    }
}

1 个答案:

答案 0 :(得分:1)

根据链接,它表示不允许扩展任何生命周期事件方法。

查看你的班级定义 -

export class Player implements OnInit {}

它表示Implements没有扩展。

角度分量的其他生命周期方法也是如此。