我一直在寻找获得当前路线路径名的好方法.这是我能找到的最容易的.
this.route.snapshot.firstChild.url[0].path
Run Code Online (Sandbox Code Playgroud)
有没有更好的办法?谢谢!
我不确定为什么变化检测在这里不起作用.我尝试过一些东西,包括一个setTimeout.我正在使用RC5.基本上我想根据我的URL中的参数更改内容.应该很简单吧?
thanks.ts
import { Component } from '@angular/core';
import { Card } from '../../components/card/card';
import { ActivatedRoute } from '@angular/router';
@Component({
selector: 'sd-thanks',
styleUrls: ['thanks.css'],
directives: [Card],
templateUrl: 'thanks.html'
})
export class Thanks {
params: any;
coming: any;
constructor(public route: ActivatedRoute) {
this.params = this.route.params.subscribe(
params => {
this.coming = params['coming'];
console.log(this.coming); // this consoles the correct true/false value
}
);
}
}
Run Code Online (Sandbox Code Playgroud)
thanks.html
<card>
<div *ngIf="coming" class="card-content">
<span class="card-title">We can't wait to see you!</span>
</div>
<div *ngIf="!coming" class="card-content">
<span …
Run Code Online (Sandbox Code Playgroud) javascript angular2-routing angular2-changedetection angular
他们刚刚更新了Ionic 2以使用Angular 2 RC1,这很棒,除了路由对我来说仍然有点奇怪.我试图跟随更新指南,但我的导航仍未定义.旧的getComponent方法有效,但是他们通过此更新摆脱了这种方法.它适用于组件或页面,但不适用于服务.
我得到的错误是 No provider for NavController!
import {IonicApp, NavController, Nav} from 'ionic-angular';
import {Injectable, ViewChild} from '@angular/core';
import {Http, HTTP_PROVIDERS, Headers} from '@angular/http';
import {HomePage} from '../pages/home/home';
@Injectable()
export class User {
isLoggedIn: boolean = false;
username: string = 'jaruesink';
constructor (public nav: NavController) {
}
login(username) {
this.isLoggedIn = true;
this.username = username;
this.nav.push(HomePage);
}
logout() {
this.isLoggedIn = false;
}
}
Run Code Online (Sandbox Code Playgroud) 我知道这很糟糕,因为大多数人都喜欢看这里的代码.然而,我正在尝试为我的小型企业制作一个广泛的计算器,而且我做了很多错事.
请不要更正我的所有代码,这将是太多的工作.但我想知道是否有一种方法可以在隐藏元素时不运行jQuery.
我为每种产品类型和我的代码编写方式都有几个计算器,它只对第一个元素ID有效,即使它是隐藏的.
这是我正在处理的计算器的链接:http://www.virtualbookworm.com/productioncalcnew.php