2017-05-24 114 views
2

我有這個在我的HTML:如何逃避花括號中的角

<iframe src="https://kart.1881.no/?direction={59.83006424|6.25588723|START}{{{latitude}}|{{longitude}}|M%C3%85L}"></iframe> 

通知 {{{latitude}} - 在這裏,我想逃離第一{

我試圖把\{,但它無法正常工作以及。

的錯誤是Missing expected : at the end of the expression

+0

的可能的複製[如何在Angular2中爲模板的一部分禁用模板綁定?](https://stackoverflow.com/questions/368 21734 /如何禁用模板綁定在模板中的部分角度) – JayChase

+0

不要使用AngularJS標籤的問題關於Angular 2請 – Mistalis

回答

1

視圖

<iframe [src]="'https://kart.1881.no/?direction={59.83006424|6.25588723|START}{' + latitude + '|' + longitude + '|M%C3%85L}' | safe"></iframe> 

而下水管應該幫助你

import { Pipe, PipeTransform } from '@angular/core'; 
import { DomSanitizer} from '@angular/platform-browser'; 

@Pipe({ name: 'safe' }) 
export class SafePipe implements PipeTransform { 
    constructor(private sanitizer: DomSanitizer) {} 
    transform(url) { 
     return this.sanitizer.bypassSecurityTrustResourceUrl(url); 
    } 
} 

您可以覆蓋插值像

template: ` 
    <iframe src="https://kart.1881.no/?direction={59.83006424|6.25588723|START}{[[latitude]]|[[longitude]]|M%C3%85L}"></iframe> 
    `, 
interpolation: ['[[', ']]'] 

但無論如何你必須消毒url將財產(不插值)只工作結合

Plunker Example

1

您可以用%7B嘗試{%7D}。這些只是URI編碼的形式,Angular不應該試圖解析。

+0

不起作用錯誤:不安全的值用於資源URL上下文中(請參閱http://g.co/ng/security#xss) –

0

使用+運算符來連接所需的SRC

src="...{' + {{latitude}}+ '}...'"

+0

您必須將'src'更改爲'[src]'才能這樣做 – trichetriche

+0

不使用'[]' – AngJobs

+0

派對正確。但它會給出與\t 相同的錯誤不起作用錯誤:資源URL上下文中使用的不安全值 –