小编Vis*_*shu的帖子

如何将组件导入Angular 2中的另一个根组件

我试图从一个文件导入组件另一个根组件文件.它给出了错误..

zone.js:484未处理的Promise拒绝:模板解析错误:'courses'不是已知元素:1.如果'courses'是Angular组件,则验证它是否是此模块的一部分.2.如果"courses"是Web组件,则将"CUSTOM_ELEMENTS_SCHEMA"添加到此组件的"@NgModule.schema"以禁止显示此消息.("

我的第一个Angular 2 App

[错误 - >]"):AppComponent @ 0:31;区域:;任务:Promise.then;值:错误:模板解析错误:(...)错误:模板解析错误:'courses'不是已知元素:

我的app.component.ts就像[根组件文件]

import { Component } from '@angular/core';
import {CoursesComponent} from './courses.component';

@Component({
  selector: 'my-app',
  template: '<h1>My First Angular 2 App</h1><courses></courses>',
  directives:[CoursesComponent],
})

export class AppComponent { }
Run Code Online (Sandbox Code Playgroud)

和我的courses.component.ts是;

import { Component } from '@angular/core';
@Component({
  selector: 'courses',
  template: '<h1>courses</h1>'
})
export class CoursesComponent { }
Run Code Online (Sandbox Code Playgroud)

从app.component中的courses.component.ts文件导入课程组件时,我无法在其中声明指令 @Component{}

directives:[CoursesComponent] 给我错误

请告知解决方案.

angular2-directives angular

51
推荐指数
4
解决办法
11万
查看次数

如何在Angular 2中获取JSON文件

因为我是Angular的新手,任何人都可以使用angular 2来提供一个简单的解决方案来加载JSON文件数据.

我的代码如下

的index.html

<html>
  <head>
    <title>Angular 2 QuickStart</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="css/styles.css">
    <!-- 1. Load libraries -->
     <!-- Polyfill(s) for older browsers -->
    <script src="node_modules/core-js/client/shim.min.js"></script>
    <script src="node_modules/zone.js/dist/zone.js"></script>
    <script src="node_modules/reflect-metadata/Reflect.js"></script>
    <script src="node_modules/systemjs/dist/system.src.js"></script>
    <!-- 2. Configure SystemJS -->
    <script src="systemjs.config.js"></script>
    <script>
      System.import('app').catch(function(err){ console.error(err); });
    </script>
  </head>
  <!-- 3. Display the application -->
  <body>
    <my-app>Loading...</my-app>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

app.component.ts

import {Component} from '@angular/core';
  
@Component({
  selector: 'my-app',
  template: `
          <div id="main">
            Main Div
               <div id = "header"></div>
               <div id …
Run Code Online (Sandbox Code Playgroud)

json angular

36
推荐指数
6
解决办法
12万
查看次数

标签 统计

angular ×2

angular2-directives ×1

json ×1