相关疑难解决方法(0)

警告:清理不安全的样式值url

我想在我的Angular 2应用程序中的组件模板中设置DIV的背景图像.但是我在我的控制台中不断收到以下警告,但是我没有达到预期的效果......我不确定动态CSS背景图像是否因为Angular2中的安全限制或者我的HTML模板被破坏而被阻止.

这是我在控制台中看到的警告(我已将我的img网址更改为/img/path/is/correct.png:

警告:清理不安全的样式值url(SafeValue必须使用[property] = binding:/img/path/is/correct.png(请参阅http://g.co/ng/security#xss))(请参阅http:// g.co/ng/security#xss).

问题是我使用DomSanitizationServiceAngular2中的方法清理注入模板的内容.这是我在模板中的HTML:

<div>
    <div>
        <div class="header"
             *ngIf="image"
             [style.background-image]="'url(' + image + ')'">
        </div>

        <div class="zone">
            <div>
                <div>
                    <h1 [innerHTML]="header"></h1>
                </div>
                <div class="zone__content">
                    <p
                       *ngFor="let contentSegment of content"
                       [innerHTML]="contentSegment"></p>
                </div>
            </div>
        </div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

这是组件......

Import {
    DomSanitizationService,
    SafeHtml,
    SafeUrl,
    SafeStyle
} from '@angular/platform-browser';

@Component({
               selector: 'example',
               templateUrl: 'src/content/example.component.html'
           })
export class CardComponent implements OnChanges {

    public header:SafeHtml;
    public content:SafeHtml[];
    public image:SafeStyle;
    public isActive:boolean;
    public isExtended:boolean;

    constructor(private …
Run Code Online (Sandbox Code Playgroud)

xss typescript angular

84
推荐指数
7
解决办法
10万
查看次数

角度2中的样式绑定backgrounImage抛出错误

我正在尝试使用angular 2创建一个应用程序,这是我的模板:

<div class="cover_user_profile"
       [style.backgroundImage]="model.cover ? url(model.cover) : url('client/img/profile_user/test.png') ">
</div>
Run Code Online (Sandbox Code Playgroud)

我认为angular2认为url()是一个函数并抛出错误......这个问题的解决方案是什么?

angular

3
推荐指数
1
解决办法
1130
查看次数

标签 统计

angular ×2

typescript ×1

xss ×1