我正试图通过配置文件组件(前一个组件)导航到listProfiles组件.我正在使用ActivatedRoute并试图通过导航到它this.router.navigate(['/listProfiles)
组件中应该导航到listProfile组件的代码
import {ActivatedRoute, Router} from '@angular/router';
constructor(private router: ActivatedRoute){}
deleteProfile():void{
this.router.navigate(['/listProfiles']); //Gives the error message in the title
}
Run Code Online (Sandbox Code Playgroud)
app.module.ts
import { ListProfilesComponent } from './list-profiles/list-profiles.component';
import { ProfileComponent } from './profile/profile.component';
const appRoutes: Routes = [
{ path: 'addProfile', component: AddProfileComponent },
{ path: 'listProfiles', component: ListProfilesComponent},
{ path: 'profile/:id', component: ProfileComponent},
{ path: 'login', component: LoginComponent}
];
@NgModule({
declarations: [
AppComponent,
ListProfilesComponent,
ProfileComponent,
],
imports: [
FormsModule,
ReactiveFormsModule,
NoopAnimationsModule,
BrowserModule,
HttpModule,
RouterModule.forRoot(
appRoutes, …Run Code Online (Sandbox Code Playgroud) 我正在尝试将毫秒转换为可读的小时、分钟、秒格式。我尝试过手动执行此操作,但我陷入困境,我觉得应该有一种更简单的方法。
当前手写秒表:
ngOnInit(){
//alert(this.datePipe.transform(new Date()));
let timer = Observable.timer(0, 1000);
timer.subscribe(t=>{
this.today = this.datePipe.transform(t);
this.second = t;
if(this.second==60){
this.second = 0;
this.minute += 1;
}else if(this.minute == 60){
this.minute = 0;
this.hour += 1;
}
});
}
Run Code Online (Sandbox Code Playgroud)
一旦 t 超过 60 秒,秒数将不会重置,并且将继续超过 60。
所以我的问题是,有没有一种更简单、更有效的方法?我读过这篇文章,但不太明白它在我的示例DatePipe中是如何工作的
超文本标记语言
<div class="client-time">
<span>Client time</span>
<br/>
<strong>{{hour}}:{{minute}}:{{second}}</strong>
</div>
</footer>
Run Code Online (Sandbox Code Playgroud)
基本上我试图显示用户在页面上停留的时间。
我正在尝试将文本复制到 h3 标签内的剪贴板。我在 copyText.select() 代码行收到以下错误。
未捕获的类型错误:copyText.select 不是 HTMLDivElement 中的函数。
编辑:在输入标签上使用时,复制到剪贴板功能有效,但在 h3 标签内时无效。
<div class="colorDiv" id="firstColorObject">
<h3 class="colorCode" id="p1" value="123">#Color 1</h3>
</div>
Run Code Online (Sandbox Code Playgroud)
document.querySelector("#firstColorObject").addEventListener("click", function(){
var copyText = document.getElementById("p1");
copyText.select();
document.execCommand("copy");
alert("Copied the text: " + copyText.value);
}, false);
Run Code Online (Sandbox Code Playgroud) angular ×2
clipboard ×1
copy ×1
datetime ×1
formatting ×1
html ×1
javascript ×1
url-routing ×1