Tag: angular

Angular 2:为什么在检索路由参数时使用switchMap?

我正在阅读关于路由和导航的Angular Guide 。 他们使用这个代码来检索路由器的参数'id'并用它来获得service服务的英雄: ngOnInit() { this.route.params .switchMap((params: Params) => this.service.getHero(+params['id'])) .subscribe((hero: Hero) => this.hero = hero); } 但是我不明白在上面的代码中使用switchMap操作符的目的是什么。 下面的代码不会一样吗? ngOnInit() { this.route.params // NOTE: I do not use switchMap here, but subscribe directly .subscribe((params: Params) => { this.service.getHero(+params['id']).then(hero => this.hero = hero) }); }

Angular2 – 如何从应用程序外部调用组件函数

我正在使用一个有callback的JavaScript对象。 我希望一旦callback被触发来调用Angular2组件中的函数。 示例HTML文件。 var run = new Hello('callbackfunction'); function callbackfunction(){ // how to call the function **runThisFunctionFromOutside** } <script> System.config({ transpiler: 'typescript', typescriptOptions: { emitDecoratorMetadata: true }, packages: {'js/app': {defaultExtension: 'ts'}} }); System.import('js/app/main') .then(null, console.error.bind(console)); </script> 我的App.component.ts import {Component NgZone} from 'angular2/core'; import {GameButtonsComponent} from './buttons/game-buttons.component'; @Component({ selector: 'my-app', template: ' blblb' }) export class […]

如何在要素模块层次结构中使用.forRoot()

任何人都可以请澄清我怎么应用.forRoot()调用结构多个嵌套的function模块层次结构? 例如,如果我有这样的模块: – MainModule – SharedModule – FeatureModuleA – FeatureModuleA1 – FeatureModuleA2 – FeatureModuleB 所有function模块都有一个.forRoot()静态函数。 我应该如何定义FeatureModuleA以“传递”.forRoot()函数? @NgModule({ imports: [ //- I can use .forRoot() calls here but this module not the root module //- I don't need to import sub-modules here, FeatureA only a wrapper //FeatureModuleA1.forRoot(), //WRONG! //FeatureModuleA2.forRoot(), //WRONG! ], exports: [ //I cannot use […]

Angular 2中的本地存储

我需要将数据存储在浏览器的会话中,并检索数据,直到会话退出。 你如何在Angular 2中使用本地和会话存储?

如何索引Golangstring中的字符?

如何获得“E”输出而不是69? package main import "fmt" func main() { fmt.Print("HELLO"[1]) } Golang是否有将字符转换为字节的function?

asp.net身份获取login用户的所有angular色

我创build了一个基于angular色的菜单,我按照这个教程。 在那个页面的一些地方你会看到这行代码: String[] roles = Roles.GetRolesForUser(); 它返回当前login用户的所有angular色。 我想知道如何用新的ASP.NET身份系统来实现这个function? 这还是很新的,没有什么可以find的。

我该如何提高Angular2应用程序的负载性能?

Angular2的应用程序加载速度慢,我怎样才能提高性能的负载? 我使用Angular2,使用html5打字。 目前我的应用程序需要4秒加载。 我使用Firebase托pipe并使用cloudflare。 我正在做的事情/信息: 我压缩了图像。 我缩小CSS 我把js缩小了。 我在脚本上使用asynchronous。 我的脚本在我的。 脚本大约700kb 我用谷歌速度testing,并得到65% 我使用的库的缩小版本,例如bootstrap等 使用systemjs。 这是使用的种子应用程序: https : //github.com/mgechev/angular-seed stream: 当应用程序加载它显示一个蓝色的屏幕(这是引导的CSS),然后4秒后,应用程序加载和工作非常快。 但需要4秒加载。 这似乎是systemjs最小化的app.js文件正在减慢整个应用程序,而不是足够快地显示视图。 这是我的网站速度testing: https : //www.webpagetest.org/result/161206_F5_N87/ 这是我的网站: https://thepoolcover.co.uk/ 让我知道,如果你需要更多的信息关于我的应用程序和我可以做的任何其他事情。

tslint / codelyzer / ng lint错误:“for(… in …)语句必须使用if语句过滤”

林特错误信息: src / app / detail / edit / edit.component.ts [111,5]:for(… in …)语句必须用if语句过滤 代码片段(这是一个工作代码,也可以在angular.io表单validation部分获得 ): for (const field in this.formErrors) { // clear previous error message (if any) this.formErrors[field] = ''; const control = form.get(field); if (control && control.dirty && !control.valid) { const messages = this.validationMessages[field]; for (const key in control.errors) { this.formErrors[field] += messages[key] […]

Angular 2checkbox双向数据绑定

我是相当新的Angular2,我有一个小问题:在我的login组件HTML中,我有两个checkbox,我想以两种方式绑定到login组件TypeScript的数据绑定。 这是HTML: <div class="checkbox"> <label> <input #saveUsername [(ngModel)]="saveUsername.selected" type="checkbox" data-toggle="toggle">Benutername speichern </label ></div> 这是Component.ts: import { Component, OnInit } from '@angular/core'; import { Router } from '@angular/router'; import { Variables } from '../../services/variables'; @Component({ selector: 'login', moduleId: module.id, templateUrl: 'login.component.html', styleUrls: ['login.component.css'] }) export class LoginComponent implements OnInit { private saveUsername: boolean = true; private […]

在configuration文件中设置ng服务器的默认主机和端口

我想知道如果我可以在configuration文件中设置主机和端口,所以我不必input ng serve –host foo.bar –port 80 而不是仅仅 ng serve