2016-08-08 3 views
1

新しいAngular 2アプリ(rc4)にng2-treeプラグインをインストールしましたが、その後はthisに従っています。プラグインがインストールされ、node_modulesフォルダーにあります。NG2 Angular 2の新しいアプリにインストールした後にツリーモジュールが見つかりません

私は、このコンポーネントでそれを使用しようとしました:

import {Component} from '@angular/core'; 
import {TreeModel, TreeComponent} from "ng2-tree"; 

@Component({ 
    selector: 'tree-side', 
    templateUrl: '../../pages/tree-side.html', 
    directives: [TreeComponent] 

}) 
export class TreeSideComponent{ 
    private tree: TreeModel = { 
     value: 'Programming languages by programming paradigm', 
     children: [ 
      { 
       value: 'Object-oriented programming', 
       children: [ 
        {value: 'Java'}, 
        {value: 'C++'}, 
        {value: 'C#'} 
       ] 
      }, 
      { 
       value: 'Prototype-based programming', 
       children: [ 
        {value: 'JavaScript'}, 
        {value: 'CoffeeScript'}, 
        {value: 'Lua'} 
       ] 
      } 
     ] 
    }; 
} 

しかし、私は、NPMコンソールにこのエラーが表示されます。私は次のようにsystem.config.jsを変更した

404 GET /ng2-tree 

コード、回避策を見つけようとして:

var map = { 
    ... 
    'ng2-tree':     'node_modules/ng2-tree' 
}; 
// packages tells the System loader how to load when no filename and/or no extension 
var packages = { 
    ... 
    'ng2-tree':     { defaultExtension: 'js' }, 
}; 

しかし、私は後にこのエラーが発生します。

Error loading http://localhost:3000/node_modules/ng2-tree as "ng2-tree" from http://localhost:3000/app/pages/tree.component.js 

Thierry Templierの指示に従って、私はこの他の構成を試しました。 lodashプラグインの設定を含めて、これはng-tree依存関係を修正した後にng-treeと同じ問題があったためです。

var map = { 
... 
     'ng2-tree':     'node_modules/ng2-tree', 
     'lodash':     'node_modules/lodash' 
    }; 
    // packages tells the System loader how to load when no filename and/or no extension 
    var packages = { 
... 
     'ng2-tree':     { main: 'index.js', defaultExtension: 'js' }, 
     'lodash':     { main: 'index.js', defaultExtension: 'js' } 
    }; 

しかし、このケースで私が得た:

[1] 16.08.08 12:04:09 404 GET /tree.component.html 
[1] 16.08.08 12:04:09 404 GET /node-menu.component.html 

Failed to load tree.component.html ; Zone: angular ; Task: Promise.then ; Value: Failed to load tree.component.html 

は、どうやらこれは、相対パスの解決が原因ですが、どんな場合でも、この質問には対応しておりません。

答えて

0

私はあなたがNG2-ツリーのpackages構成でmainプロパティを逃したと思います:TreeModuleをロードしようとしたとき、私は問題があった

var packages = { 
    ... 
    'ng2-tree': { main: 'index.js', defaultExtension: 'js' }, 
}; 
+0

\node_modules\ng2-tree変更

"devDependencies": { "@angular/cli": "1.1.1", } 

内部package.configファイルでは、私が試したし、その後、私はNPMに、このエラーを得た:16.08.08 11時49分55秒404 GET/lodash。このプラグインでも同じことをする必要がありますか? – quindimildev

+0

"on NPM"とはどういう意味ですか?アプリケーションを実行するときですか?もしそうなら、ng2-treeはSystemJSの設定で設定する必要のあるlodash依存関係を持っているようです... –

+0

私は、プロジェクトを実行しているときにコンソールにそのエラーが表示されることを意味します。ブラウザーのインスペクターで、エラーは次のとおりです。http:// localhost:3000/lodashをhttp:// localhost:3000/node_modules/ng2-tree/src/tree.component.jsから "lodash"としてロード中にエラーが発生しました。私はlodashプラグインと同じにしようとしたが、エラーは他のものです:tree.component.htmlを読み込めませんでした – quindimildev

0

。私はこの問題を解決しました。問題は@angular/cliバージョンで発生しました。

"devDependencies": { 
    "@angular/cli": "#####",// version of your @angular/cli(**You can find it from package.config file in the root folder**) 
} 
関連する問題