小编Pet*_*ete的帖子

Angular 2 - EXCEPTION:错误:资源URL上下文中使用的不安全值

我收到以下错误:

Angular 2 - EXCEPTION:错误:资源URL上下文中使用的不安全值

是否与在启动时不立即使用媒体项目有关?或者它与URL不安全有关?我正在努力消毒它.

export class HomeComponent {

  sanitizer: DomSanitizationService;
  errorMessage: string;
  activeMedia: MediaItem = new MediaItem(0, '', '', '', '', '', '');

  constructor(
    private mediaStorage: MediaStorageService, 
    private harvesterService: HarvesterService, 
    sanitizer: DomSanitizationService) {

    this.sanitizer = sanitizer;
    // Initial call - 
    harvesterService.getMediaItems(10, 'type', 'category');
    let subscription = harvesterService.initialMediaHarvestedEvent.subscribe(() => {
      this.activeMedia = mediaStorage.mediaList[0];
      let newURL = this.activeMedia.URL + '?rel=0&autoplay=1';
      newURL = newURL.replace('watch?v=', 'v/');
      this.activeMedia.URL = newURL; //sanitizer.bypassSecurityTrustUrl(newURL);
      console.log(newURL);
    });
  }

  cleanURL(oldURL: string): SafeResourceUrl {
    return this.sanitizer.bypassSecurityTrustUrl(oldURL);
  }
}
Run Code Online (Sandbox Code Playgroud)

模板代码是: …

javascript typescript angular

25
推荐指数
1
解决办法
2万
查看次数

Angular 2 - (SystemJS)模块'GalleryModule'导入的意外指令'ViewerComponent'

我收到以下错误,不知道该怎么做:

(SystemJS)ViewerComponent模块导入的意外指令GalleryModule

感谢您提供有关可能导致错误的任何帮助.在主应用程序中,它导入库模块.gallery组件将查看器组件作为子组件.

图库组件:

import {Component, NgZone, ViewChild, ElementRef} from '@angular/core';
import {Http, Response} from '@angular/http';
import { ViewerComponent } from '../viewer/viewer.component';
import 'rxjs/Rx';

interface IImage {
  url: string;
  thumbnail: string;
  date: string;
  width: number;
  height: number;
}

@Component({
  selector: 'sd-gallery',
  templateUrl: 'gallery.component.html',
  styleUrls: ['gallery.component.css']
})
export class GalleryComponent {;
  @ViewChild('galleryContainer') galleryContainer: ElementRef;
  @ViewChild('asyncLoadingContainer') asyncLoadingContainer: ElementRef;

  thumbnailBasePath = 'assets/img/gallery/preview_xxs/';
  currentIdx: number = 0;
  galleryBasePath: string = 'assets/img/gallery/';
  showBig: boolean = false;
  images: any[] = [{ url: '' …
Run Code Online (Sandbox Code Playgroud)

angular2-modules angular

7
推荐指数
1
解决办法
5827
查看次数

Angular2 - 除非单击,否则不会显示更改检测

我有一个组件,您可以在其中输入一些搜索词,它将使用*ngFor循环过滤内容.问题是当我输入搜索词时,我需要点击屏幕以使更新生效.

以下是发生循环的html代码的一部分:

    <li *ngFor="let item of posts | reverse; let i = index; ">
        <div class="media" *ngIf="item.doesContainTags(searchTags)">
Run Code Online (Sandbox Code Playgroud)

在输入要搜索的标记的输入字段上执行的代码是:

 updateSearchTags() {
    event.stopPropagation();
    // sorter is what is types into the search by tag input field
    this.searchTags = this.sorter.split(',');
 }
Run Code Online (Sandbox Code Playgroud)

这是post对象的静态函数:

  doesContainTags(searchTags: string[]): boolean {

    let array = this.tags.split(',');
    if(!array || array.length === 0) {return false;}
    if(!searchTags || searchTags.length === 0) {return false;}

    for(let searchTag of searchTags){
         if(array.indexOf(searchTag) === -1) {

        } else {
        return true;
        }
    }
    return false;
 }
Run Code Online (Sandbox Code Playgroud)

这是获取循环的帖子的代码: …

angularfire2 angular

7
推荐指数
1
解决办法
4078
查看次数

Angular2 - *ngIf 路由是某个参数

我有一条路线 /main/item:id

看起来像:

http://localhost:5000/main/item/-JJHkhfghsiu45ve
Run Code Online (Sandbox Code Playgroud)

在我的 html 中,我希望能够使用 *ngIf 来显示是否这是路线。我不想为此使用路由器插座。

我遇到的问题可能与参数有关。

我正在做类似的事情:

 <div *ngIf="this.router.url !== '/main/item:id'">
Run Code Online (Sandbox Code Playgroud)

但这对我不起作用,因为它认为这总是错误的。谢谢

angular

2
推荐指数
1
解决办法
1万
查看次数