Angular ui路由使用参数导航

时间:2018-10-01 05:56:09

标签: angular navigation angular-ui-router console.log

html中,有两个按钮用户调查-

<button *ngIf="isUserAdmin" mat-button (click)="listSurveys()">Survey</button>
<button *ngIf="isUserAdmin" mat-button (click)="list('users')">Users</button>

.ts文件中,我有两种方法可以导航到相应的列表页面-

 listSurveys(): void {
    this.router.navigate(['surveys']);
  };

  listUsers(): void {
    this.router.navigate(['users']);
  };  

以上设置按预期工作。但是我只想用 listUsers()/listSurveys() 这样的方法替换 list(items: String)

.HTML:

<button *ngIf="isUserAdmin" mat-button (click)="list('surveys')">Survey</button>
<button *ngIf="isUserAdmin" mat-button (click)="list('users')">Users</button>

.TS:

list(items : String) {
    console.log("\'" +items+ "\'");
    this.router.navigate(["\'" +items+ "\'"]);
  }

尽管the console.log()会在控制台中分别记录“调查”和“用户”,但这是行不通的。有人可以帮忙吗?预先感谢。

2 个答案:

答案 0 :(得分:2)

我认为这会起作用

list(items : String) {
    console.log(items);
    this.router.navigate([items]);
  }

答案 1 :(得分:1)

HTML

df.resample('W').ffill().agg(lambda x: x/4)
df.resample('D').ffill().agg(lambda x: x/30)
and need to use calendar.monthrange(2012,1)[1] to identify days 
def func_count_number_of_weeks(df):
    return len(calendar.monthcalendar(df['DateRange'].year, df['DateRange'].month))

def func_convert_from_monthly(df, col, category, columns):
    if category == "Daily":
        df['number_of_days'] = df['DateRange'].dt.daysinmonth
        for column in columns:
            df[column] = df[column] / df['number_of_days'] 
        df.drop('number_of_days', axis=1, inplace=True)
    elif category == "Weekly":
        df['number_of_weeks'] = df.apply(func_count_number_of_weeks, axis=1)
        for column in columns:
            df[column] = df[column] / df['number_of_weeks'] 
        df.drop('number_of_weeks', axis=1, inplace=True)

    return df

def func_resample_from_monthly(df,col, category):
    df.set_index(col, inplace=True)
    df.index = pd.to_datetime(df.index, dayfirst=True)
    if category == "Monthly":
        df = df.resample('MS').ffill()
    elif category == "Weekly":
        df = df.resample('W').ffill()

    return df

TS

<button *ngIf="isUserAdmin" mat-button (click)="list('surveys')">Survey</button>
<button *ngIf="isUserAdmin" mat-button (click)="list('user')">User</button>

了解详情 https://angular.io/guide/router