0

我整天都在努力打字以使用 angular2-materialize 和 materialize-css,但运气不佳。

我使用 npm install 和 save 选项安装了两者。

这是我遇到的错误之一:

(index):29 错误: SyntaxError: Unexpected token <(...)

这一行是:

<script src="systemjs.config.js"></script>

建议?

systemjs.config.js

(function (global) {
  System.config({
    paths: {
      // paths serve as alias
      'npm:': 'node_modules/'
    },
    // map tells the System loader where to look for things
    map: {
      // our app is within the app folder
      app: 'app',
      // angular bundles
      '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
      '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
      '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
      '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
      '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
      '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
      '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
      '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
      // other libraries
      'rxjs': 'npm:rxjs',
      'angular2-in-memory-web-api': 'npm:angular2-in-memory-web-api',
      "materialize-css": "node-modules/materialize-css",
      "angular2-materialize": "node_modules/angular2-materialize"

    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
      app: {
        main: './main.js',
        defaultExtension: 'js'
      },
      rxjs: {
        defaultExtension: 'js'
      },
      'materialize-css': {
        "format": "global",
        "main": "dist/js/materialize",
        "defaultExtension": "js"
      },
      'angular2-materialize': {
        "main": "dist/index",
        "defaultExtension": "js"
      }
    }
  });
})(this);

app.component.ts

import { Component } from '@angular/core';
import 'node_modules/materialize-css';
import 'node_modules/angular2-materialize';


@Component({
    selector: 'shows-app',
    templateUrl: 'app/app.component.html',
    styleUrls: ['app/material.min.css']
})
export class AppComponent {
    pageTitle: string = 'NetShows';
    showMenu: boolean = true;
    public loggedIn: boolean = false;

    public menuButtonClick() {
        this.showMenu = !this.showMenu;
    }
}

索引.html

<!DOCTYPE html>
<html style="html, body {height:100;padding:0;margin:0}">

<head lang="en">
    <base href=".">
    <title>NetShows Horse Show Management</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="app/app.component.css" rel="stylesheet" />
    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">

    <!--<link rel="stylesheet" href="node_modules/material-design-lite/dist/material.light_blue-amber.min.css" />-->
    <link rel="stylesheet" href="https://code.getmdl.io/1.2.1/material.indigo-pink.min.css">
    <!-- Material Design icon font -->
    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
    <script defer src="node_modules/material-design-lite/dist/material.min.js"></script>
    <!-- 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>
    <script src="https://code.getmdl.io/1.2.1/material.min.js"></script>

    <!-- Configure SystemJS -->
    <script src="systemjs.config.js"></script>
    <script>
      System.import('app').catch(function(err){ console.error(err);  });
    </script>
</head>

<body>
    <shows-app>Loading App...</shows-app>
</body>

</html>
4

1 回答 1

0

解决方案:

我有两件事错了

  1. index.html 中缺少 materialize-css 样式
  2. 我的导入错误。

我将导入更改为:

import 'materialize-css';
import 'angular2-materialize';

生活很好。我以为我对 systemjs.config.js 文件做错了,但事实并非如此。

我确实在以下位置找到了一篇关于 systemjs 的精彩文章:

https://superdevelopment.com/2016/03/16/a-dive-into-systemjs-part-1/

于 2016-10-12T14:57:07.200 回答