2016-09-26 4 views
0

Я пытаюсь изменить код из урока NG2, чтобы сделать динамический проигрыватель в NG2. Когда я добавляю <h1>anything</h1> в свой шаблон в app.component.js, он работает. Когда я добавляю в + `код дает эту ошибкуУгловая 2, ошибка шаблона пробоирует простой сайт

zone.min.js:1 Unhandled Promise rejection: Template parse errors: 
'spotifyiframeplayer' is not a known element: 
1. If 'spotifyiframeplayer' is an Angular component, then verify that it is part of this module. 
2. If 'spotifyiframeplayer' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schema' of this component to suppress this message. ("<h1>Spotify Iframe Player</h1>[ERROR ->]<spotifyiframeplayer></spotifyiframeplayer>"): [email protected]:30 ; Zone: <root> ; Task: Promise.then ; Value: Error: Template parse errors:(…) Error: Template parse errors: 
'spotifyiframeplayer' is not a known element: 
1. If 'spotifyiframeplayer' is an Angular component, then verify that it is part of this module. 
2. If 'spotifyiframeplayer' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schema' of this component to suppress this message. ("<h1>Spotify Iframe Player</h1>[ERROR ->]<spotifyiframeplayer></spotifyiframeplayer>"): [email protected]:30 
    at TemplateParser.parse (https://unpkg.com/@angular/[email protected]/bundles/compiler.umd.js:8530:21) 
    at RuntimeCompiler._compileTemplate (https://unpkg.com/@angular/[email protected]/bundles/compiler.umd.js:16905:53) 
    at https://unpkg.com/@angular/[email protected]/bundles/compiler.umd.js:16828:85 
    at Set.forEach (native) 
    at compile (https://unpkg.com/@angular/[email protected]/bundles/compiler.umd.js:16828:49) 
    at e.invoke (https://unpkg.com/[email protected]/dist/zone.min.js:1:15936) 
    at n.run (https://unpkg.com/[email protected]/dist/zone.min.js:1:13323) 
    at https://unpkg.com/[email protected]/dist/zone.min.js:1:11425 
    at e.invokeTask (https://unpkg.com/[email protected]/dist/zone.min.js:1:16565) 
    at n.runTask (https://unpkg.com/[email protected]/dist/zone.min.js:1:13925)o @ zone.min.js:1a @ zone.min.js:1a @ zone.min.js:1 
zone.min.js:1 Error: Uncaught (in promise): Error: Template parse errors:(…)o @ zone.min.js:1a @ zone.min.js:1a @ zone.min.js:1 

Link to Plunker Я не знаю, как исправить эту ошибку. Я проверил, и элемент упоминается только один раз в примере кода и работает для этого проекта.

@galvon (это также на plunker)

(function(app) { 
    var Component = ng.core.Component; 

    app.AppComponent = Component({ 
    selector: 'my-app', 
    template: 
     ` 
     <h1>Spotify Iframe Player</h1> 
     <spotifyiframeplayer></spotifyiframeplayer> 
     ` 
    }) 
    .Class({ 
    constructor: function AppComponent() { } 
    }); 

})(window.app || (window.app = {})); 
+0

Пожалуйста, разместите свой шаблон, что-то недействительно (синтаксис) – galvan

+1

Где вы определяете компонент «spotifyiframeplayer». Вы должны добавить этот компонент в свойство 'declarations' вашего модуля – yurzui

+0

. Попробую объявить его в app.component.js – drew4452862

ответ

1

не используют + для добавления строк.

использовать многострочный HTML, вы можете использовать обратные одиночные кавычки (найти в клавиатуре - ` ), как показано ниже,

template: 
     '<h1>Spotify Iframe Player</h1>' + 
     '<spotifyiframeplayer></spotifyiframeplayer>' 

изменение его

template: 
     ` 
     <h1>Spotify Iframe Player</h1> 
     <spotifyiframeplayer></spotifyiframeplayer> 
     ` 

ПРИМЕЧАНИЕ: Помимо этого, ваш плункер является неполным, поэтому даже после этого chan ge не ожидает, что plunker будет запущен, так как у вас нет реализации компонента spotifyiframeplayer.

+0

пытаясь заставить это работать ... похоже, та же проблема. Я положил back-ticks и попытался скопировать \ вставить. Кажется, что не работает на plunker либо – drew4452862

+0

. Пожалуйста, прочтите мой текст ПРИМЕЧАНИЕ – micronyks

+0

@micronyks почему '+' не будет работать (более старый путь)? –