我正在学习Angular 2+,我很难理解导入/导出在ngModule中的作用.更具体地说,如果您要使用es6语法导入模块,为什么导入模块很重要
import { BrowserModule } from '@angular/platform-browser';
@NgModule({
imports: [ BrowserModule ],
providers: [ Logger ],
declarations: [ AppComponent ],
exports: [ AppComponent ]
})
Run Code Online (Sandbox Code Playgroud)
通过es6语法检测模块是不是更简单?
导入 - 此模块中声明的组件模板需要导出类的其他模块.
但是我们已经在组件级别上导入了那些.我错过了什么吗?我也在寻找他们为什么选择这种语法的一些例子.
我的API调用使用JWT进行身份验证.我正在尝试为服务方法编写代码.所有请求都有这个拦截器:
public interceptBefore(request: InterceptedRequest): InterceptedRequest {
// Do whatever with request: get info or edit it
this.slimLoadingBarService.start();
let currentUser = JSON.parse(localStorage.getItem('currentUser'));
if (currentUser && currentUser.data.token) {
request.options.headers.append('Authorization', 'Bearer ' + currentUser.data.token);
}
return request;
}
Run Code Online (Sandbox Code Playgroud)
我想测试的服务方法:
getAll(page: number, pageSize: number, company: string): Observable<any> {
return this.http.get(`${this.conf.apiUrl}/jobs`)
.map((response: Response) => response.json());
}
Run Code Online (Sandbox Code Playgroud)
开始代码:
import { MockBackend, MockConnection } from '@angular/http/testing';
import { Http, BaseRequestOptions, Response, ResponseOptions, RequestMethod } from '@angular/http';
import { JobListService } from './job-list.service';
import { inject, TestBed } …Run Code Online (Sandbox Code Playgroud) 我从各种演讲者那里听说,$ watch对于你的应用程序的性能是多么危险.我想知道是否有人在AngularJS应用程序中比较了Rxjs的Observable与$ watch的性能.我知道Observables将成为Angular 2的一部分.
我有一个<a>如下标签,
<a [routerLink]="[/Person']">Person</a>
Run Code Online (Sandbox Code Playgroud)
所以我想传递person.id给这个/Person路由器.我怎样才能将它传递与处理它@RouteConfig像params在1角
我想将从服务器检索到的一些HTML插入到angular2中的DOM元素中.我似乎无法找出最佳/正确的方法来做到这一点.
我不能只将{{my_data}}放入模板中,因为angular 2会自动转义HTML.
我试图编写一个html-unsafe指令,它只是直接为元素的innerHTML赋值:
/// <reference path="../../typings/typings.d.ts" />
import {Directive} from 'angular2/angular2';
import {ElementRef} from 'angular2/core';
@Directive({
selector: "[html-unsafe]",
properties: ['htmlUnsafe']
})
export class HtmlUnsafe{
constructor(private elem: ElementRef){
}
set htmlUnsafe(value){
setTimeout(() => {
this.elem.nativeElement.innerHTML = value;
},0);
}
}
Run Code Online (Sandbox Code Playgroud)
所以现在在我的模板中我有类似的东西
<td [html-unsafe]="my_data"></td>
Run Code Online (Sandbox Code Playgroud)
这是有效的,但我不确定这是否正确,并且setTimeout似乎是一个奇怪的解决方法.如果没有setTimeout,它看起来this.elem.nativeElement实际上并不是指DOM元素,而是指某种临时元素.
是否有更"正确"的angular2方式简单地将HTML插入DOM?为什么我需要在setTimeout中包装DOM操作?
我是flex-layout的新手,无法修复以下内容:
https://github.com/angular/flex-layout
我的ngFor:
<div fxLayout.xs="column">
<country fxFlex *ngFor="let country of countries" [country]="country"></country>
</div>
Run Code Online (Sandbox Code Playgroud)
结果:
如果我只想连续3个国家,换句话说,如果我想让最后一个'德国'成为下一行怎么办?
这只能通过创建多个fxLayout来实现吗?我指的是2个循环,1表示创建fxLayout的数量,另一个内循环表示我的国家组件(fxFlex项目).提前致谢!
我正在使用Docker quickstart终端在我的Windows7-64bit系统上安装基于docker的tar文件.
docker load -i some_docker_image.tar
Run Code Online (Sandbox Code Playgroud)
该命令默默地执行了一些处理并闪存输出:
Error response from daemon: Untar re-exec error: exit status 1: output:
write /usr/include/c++/4.4.4/gnu/java/net/protocol/http/Handler.h: no space left on device
Run Code Online (Sandbox Code Playgroud)
如何清理部分安装的tar包来清理不必要占用的硬盘空间?
我正在尝试关于Typescript的角度2 的官方5 Min快速入门.我按照所有步骤操作,当我运行npm start它时,我My First Angular 2 App在firefox浏览器上弹出了预期的消息.
但是,当我检查控制台时,我发现错误消息:
Error: watch node_modules/angular2/es6/dev/src/common/directives/ng_if.js ENOSPC
Run Code Online (Sandbox Code Playgroud)
我不知道它是否与我之前在npm install项目的根文件夹上运行时收到的警告消息有关:
npm WARN install Couldn't install optional dependency: Unsupported
npm WARN EPACKAGEJSON angular2-quickstart@1.0.0 No description
npm WARN EPACKAGEJSON angular2-quickstart@1.0.0 No repository field.
Run Code Online (Sandbox Code Playgroud)
有人能告诉我我的方法有什么问题吗?更详细的控制台输出如下所示:
> angular2-quickstart@1.0.0 start /home/ubuntu/jsProjects/angular2-quickstart
> concurrent "npm run tsc:w" "npm run lite"
[0]
[0] > angular2-quickstart@1.0.0 tsc:w /home/ubuntu/jsProjects/angular2-quickstart
[0] > tsc -w
[0]
[1]
[1] > angular2-quickstart@1.0.0 lite /home/ubuntu/jsProjects/angular2-quickstart
[1] > lite-server
[1]
[1] [BS] …Run Code Online (Sandbox Code Playgroud) 在我的应用程序(Angular 2/Ionic 2)中,我实现了自己的登录/身份验证.基本上它的工作方式如下:在登录时,PHP后端正在验证用户名和密码.生成令牌,然后将其发送回标题中的前端(授权).后端的响应如下:
HTTP/1.1 200 OK
Host: localhost:8080
Connection: close
X-Powered-By: PHP/5.6.28
Set-Cookie: PHPSESSID=jagagi2le1b8i7r90esr4vmeo6; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Type: application/json
Authorization: d7b24a1643a61706975213306446aa4e4157d167eaad9aac989067a329c492d3
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: X-Requested-With, Content-Type, Accept, Origin, Authorization
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Content-Length: 301
Run Code Online (Sandbox Code Playgroud)
显然有一个带有令牌的Authorization标头.CORS似乎也可以正确设置,因为我在Allow-Headers标头中看到了Authorization.
但是,当我尝试在Angular 2中获取头时,它总是返回null:
private extractDataAndSetAuthHeader(res: Response) {
// Set auth header if available.
// If not available - user is not logged in. Then
// we also have to remove …Run Code Online (Sandbox Code Playgroud) angular ×7
javascript ×3
typescript ×2
angularjs ×1
css ×1
docker ×1
dom ×1
flexbox ×1
ionic2 ×1
ios ×1
jasmine ×1
node.js ×1
objective-c ×1
observable ×1
rxjs ×1
uitextfield ×1