Javascript 双向绑定的编码值
我有一个双向绑定,在我的组件上有一个属性。其目的是从用户获取URL,然后重定向到Javascript 双向绑定的编码值,javascript,angular,Javascript,Angular,我有一个双向绑定,在我的组件上有一个属性。其目的是从用户获取URL,然后重定向到/report/ 问题是它在url上发出尖嘴声,并重新定向到report/http%3A,并错过了域 这就是我到目前为止所做的: HTML 我做错了什么?使用Angular 2提供的。这样做 import { QueryEncoder } from '@angular/http'; var encodedUrl = new QueryEncoder().encodeValue(this.testUrl); this
/report/
问题是它在url上发出尖嘴声,并重新定向到report/http%3A
,并错过了域
这就是我到目前为止所做的:
HTML
我做错了什么?使用Angular 2提供的。这样做
import { QueryEncoder } from '@angular/http';
var encodedUrl = new QueryEncoder().encodeValue(this.testUrl);
this.router.navigate(['/report/' + escapedUrl]);
另外,您要从/reports/开始,然后在之后添加http,这样就不起作用了。用户是否使用http://etc输入url?我希望编码值作为路径。例如,
/reports/http%3A%2F%2Fgoogle.com
这做了完全相同的事情。它导航到/report/http%3A
,并在domain@Guerrilla你现在能试试吗?@Guerrilla你用的是什么版本的angular?较新的版本采用数组。但是删除数组,只保留字符串。很抱歉,我删除了上一条评论,我没有注意到您也更改了方法调用。通过这种方式,我得到了一个错误,我认为它显示了一个问题:EXCEPTION:Uncaught(在promise中):错误:无法匹配任何路由。URL段:“report/http%3A/google.com”错误:无法匹配任何路由。URL段:“report/http%3A/google.com”
出于某种原因,它没有对正斜杠进行编码,并且正在破坏路由如果你手动转到report/http/:google.com,你真的得到了什么吗?
import { Component } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { Router } from '@angular/router';
@Component({
selector: "check-mobile",
templateUrl: "app/check-mobile.component.html"
})
export class CheckMobileComponent{
testUrl: string;
constructor(private router: Router)
{
}
checkMobile() : void {
var escapedUrl = encodeURI(this.testUrl);
this.router.navigateByUrl('/report/' + escapedUrl);
}
}
import { QueryEncoder } from '@angular/http';
var encodedUrl = new QueryEncoder().encodeValue(this.testUrl);
this.router.navigate(['/report/' + escapedUrl]);