我尝试安装bootstrap 4,并包含以下链接
<script src="libs/jquery/dist/jquery.min.js"></script>
<script src="libs/tether/dist/js/tether.min.js" ></script>
<script src="libs/popper.js/dist/popper.js"></script>
<script src="libs/bootstrap/dist/js/bootstrap.min.js" ></script>
Run Code Online (Sandbox Code Playgroud)
但发生以下错误:
未捕获的syntaxError:意外的令牌导出
任何想法如何解决它?
我有一个枚举:
export enum PizzaSize {
SMALL = 0,
MEDIUM = 1,
LARGE = 2
}
Run Code Online (Sandbox Code Playgroud)
但是在这里我想使用一些值:例如SMALL我想说它有2个值(0,100).我怎么能这样做?
我努力使用
export enum PizzaSize {
SMALL = {key:key, value: value},
...
}
Run Code Online (Sandbox Code Playgroud)
但是打字稿不接受这个.
如果Angular 2中的解析失败,如何重定向到另一个页面?我将此解析称为我的编辑页面,但我想处理Resolve页面中的错误
我的决心:
resolve(route: ActivatedRouteSnapshot): Promise<any>|boolean {
return new Promise((resolve, reject) => {
if (route.params['id'] !== undefined) {
this.dataService.getHttpEmpresaShow(this.endpoint_url_Get + route.params['id'])
.subscribe(
result => {
console.log("ok");
return resolve(result);
},
error => {
return resolve(error);
});
}});
Run Code Online (Sandbox Code Playgroud) 当自定义写入输入但不等待他单击按钮时,我想在 angular 2 的几个时间(许多毫秒或秒)后从输入文本中获取一个值。
我试过这个,但即使我使用debounceTime,每次按键都会发送值。
我尝试了解 debounce 和 observable,这就是我的理解,任何人都可以帮我修复我的代码:
组件.html:
<md-card-title *ngIf="!edit">{{card.title}}</md-card-title>
<input *ngIf="edit" type="text" [(ngModel)]="card.title" (ngModelChange)='rename()'/>
Run Code Online (Sandbox Code Playgroud)
组件.ts
newTitle: string;
modelChanged: Subject < string > = new Subject < string > ();
constructor()
this.modelChanged
.debounceTime(500) //before emitting last event
.distinctUntilChanged()
.subscribe(model => this.newTitle = model);
}
rename(): void {
this.renameRequest.emit(this.newTitle);
}
Run Code Online (Sandbox Code Playgroud) 我的角应用程序使用websocket与后端进行通信.
在我的测试用例中,我有2个客户端组件.Observable计时器按预期打印两个不同的客户端ID.
每个ngOnInit()还打印其客户端的id.
现在出于某种原因,对于每条消息,websocketService.observeClient()的订阅被调用2次,但this.client.id总是打印第二个客户端的值.
继承我的客户组件
@Component({
...
})
export class ClientComponent implements OnInit {
@Input() client: Client;
constructor(public websocketService: WebsocketService) {
Observable.timer(1000, 1000).subscribe(() => console.log(this.client.id));
}
ngOnInit() {
console.log(this.client.id);
this.websocketService.observeClient().subscribe(data => {
console.log('message', this.client.id);
});
}
}
Run Code Online (Sandbox Code Playgroud)
和我的websocket服务
@Injectable()
export class WebsocketService {
private observable: Observable<MessageEvent>;
private observer: Subject<Message>;
constructor() {
const socket = new WebSocket('ws://localhost:9091');
this.observable = Observable.create(
(observer: Observer<MessageEvent>) => {
socket.onmessage = observer.next.bind(observer);
socket.onerror = observer.error.bind(observer);
socket.onclose = observer.complete.bind(observer);
return socket.close.bind(socket);
}
);
this.observer = …Run Code Online (Sandbox Code Playgroud) 名称字段有一些限制,所以我试图使用指令验证名称字段,如下所示.内部指令我使用正则表达式检查有效名称,然后使用有效名称替换为文本框valueAccessor.writeValue(newVal)
这里的问题是当我试图在文本框光标跳转到最后键入某个单词的中间部分时.
@Directive({
selector: '[validateName]',
host: {
'(ngModelChange)': 'onInputChange($event, false)',
'(keydown.backspace)': 'onInputChange($event.target.value, true)',
'(focusout)': 'removeClass()'
}
})
export class NameValidator {
constructor(public model: NgControl,public renderer: Renderer, public el: ElementRef) { }
onInputChange(event, backspace) {
if (!backspace) {
// Remove invalid characters (keep only valid characters)
var newVal = event.replace(/^[0-9\s]/g, '').replace(/[^A-Za-z0-9_$]/g,'');
// Add class for invalid name.
if (/^[0-9\s]/g.test(event) || /[^A-Za-z0-9_$]/g.test(event)) {
this.renderer.setElementClass(this.el.nativeElement, 'invalid-name', true);
}
else {
this.renderer.setElementClass(this.el.nativeElement, 'invalid-name', false);
}
// set the new value
this.model.valueAccessor.writeValue(newVal);
}
} …Run Code Online (Sandbox Code Playgroud) var map,packages,var config是做什么的.并且还解释了map和package对象的所有配置属性.是否有可用配置的文档?
这是我的系统配置文件
/**
* System configuration for Angular samples
* Adjust as necessary for your application needs.
*/
(function (global) {
System.config({
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
// our app is within the app folder
app: 'app',
// angular bundles
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
// other libraries
'rxjs': …Run Code Online (Sandbox Code Playgroud) 我有一个方法需要等待一个observable完成.我知道observable非常适合随着时间的推移返回单个数据,但是我需要知道这个observable何时完全返回它的所有数据,所以我可以在它返回的对象上运行验证代码.
getCustom方法订阅了提供的url上的可观察运行,然后返回observable.
我不太确定这是否是解决这种情况的最佳方式,所以如果有人能给我任何建议或方向来处理这个问题,我将不胜感激.
private validateQuoteRetrievalAnswers(reference: string) {
// Get the risk from the server
this.riskManager.getRiskFromServer(reference);
if (this.riskManager.risk) {
// Validate risk that was returned
}
}
Run Code Online (Sandbox Code Playgroud)
getRiskFromServer(quoteReference: string) {
this.riskService.getCustom("Url").subscribe => {
// need to know when the observable has returned the risk
});
}
Run Code Online (Sandbox Code Playgroud) 我有一个Ionic应用程序,它有一个user提供程序,有一个signup()方法:
doSignup() {
// set login to same as email
this.account.login = this.account.email;
// Attempt to login in through our User service
this.user.signup(this.account).subscribe((resp) => {
this.navCtrl.push(MainPage);
}, (err) => {
//console.log('error in signup', err);
// ^^ results in 'You provided 'undefined' where a stream was expected'
//this.navCtrl.push(MainPage);
// Unable to sign up
let toast = this.toastCtrl.create({
message: this.signupErrorString,
duration: 3000,
position: 'top'
});
toast.present();
});
}
Run Code Online (Sandbox Code Playgroud)
出于某种原因,此代码从不调用成功回调,只调用错误处理程序.如果是这样,会导致您在上面的评论中看到的错误.
我的user.signup()方法如下:
signup(accountInfo: any) {
return this.api.post('register', accountInfo).share(); …Run Code Online (Sandbox Code Playgroud) 在Angular中调用我的REST服务时,没有响应头.
Angular中的登录方法
login(username: string, password: string) {
const credentials = { "username": username, "password": password };
return this.http.post(this.url, credentials)
.subscribe(
data => console.log(data), // JSON.stringify(data.headers) also is empty
error => console.log(error)
);
}
Run Code Online (Sandbox Code Playgroud)
Chrome开发工具控制台中的输出
响应{_body:"",状态:200,ok:true,statusText:"OK",标题:标题...}标题:Headers_headers:Map(0)_normalizedNames:Map(0)proto:Objectok:truestatus:200statusText:"OK "type:2url:" http:// localhost:8080/backend/rest/login "_body:"" proto:Body
但是当我向邮递员发送相同的帖子请求时,我得到了预期的结果:
Access-Control-Allow-Credentials ?true
Access-Control-Allow-Origin ?chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop
Authorization ?Bearer eyJ[...]
Connection ?keep-alive
Content-Length ?0
Date ?Mon, 12 Jun 2017 13:19:54 GMT
Server ?WildFly/10
Vary ?Origin
X-Powered-By ?Undertow/1
Run Code Online (Sandbox Code Playgroud)
REST服务
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response authenticateUser(CredentialsDTO credentialsDTO) {
try {
authService.login(credentialsDTO.getUsername(), credentialsDTO.getPassword()); …Run Code Online (Sandbox Code Playgroud) angular ×9
rxjs ×2
typescript ×2
bootstrap-4 ×1
enums ×1
javascript ×1
node.js ×1
observable ×1
popper.js ×1
rest ×1
rxjs5 ×1
systemjs ×1