[英]Angular 2 and Sails.js
We are using Sails.js for our app's backend, with Angular 2 on the front end. 我们将Sails.js用于我们的应用程序后端,前端使用Angular 2。 Before the Angular 2 rc1 release, everything worked perfectly.
在Angular 2 rc1发行之前,一切都运行良好。 I started upgrading, and have hit a few snags.
我开始升级,并遇到了一些障碍。
First off, we can't access anything in the node_modules
folder from the front end. 首先,我们无法从前端访问
node_modules
文件夹中的任何内容。 So to get by that, we have a gulp task that is taking the node_modules
we need, such as the @angular/
folder, rxjs/
, and zone.js
. 因此,为了解决这个问题,我们有一个
node_modules
任务正在使用我们需要的node_modules
,例如@angular/
文件夹, rxjs/
和zone.js
This seems to be working. 这似乎正在工作。 When I reference
js/dependencies/zone.js/dist/zone.js
in the HTML file, it pulls the file in perfectly. 当我在HTML文件中引用
js/dependencies/zone.js/dist/zone.js
时,它会将文件完美地拉入。 But then when configuring SystemJS, the files don't seem to pull in correctly. 但是随后在配置SystemJS时,文件似乎无法正确插入。
var System;
(function(global) {
// map tells the System loader where to look for things
var map = {
'app': 'js', // 'dist',
'rxjs': 'js/dependencies/rxjs',
// 'angular2-in-memory-web-api': 'angular2-in-memory-web-api',
'@angular': 'js/dependencies/@angular',
};
// packages tells the System loader how to load when no filename and/or no extension
var packages = {
'app': { main: 'main.js', defaultExtension: 'js' },
'rxjs': { defaultExtension: 'js' },
// 'angular2-in-memory-web-api': { defaultExtension: 'js' },
// '/angular2-jwt': { defaultExtension: 'js' }
};
var packageNames = [
'@angular/common',
'@angular/compiler',
'@angular/core',
'@angular/http',
'@angular/platform-browser',
'@angular/platform-browser-dynamic',
'@angular/router',
'@angular/router-deprecated',
'@angular/testing',
'@angular/upgrade',
];
// add package entries for angular packages in the form '@angular/common': { main: 'index.js', defaultExtension: 'js' }
packageNames.forEach(function(pkgName) {
packages[pkgName] = { main: 'index.js', defaultExtension: 'js' };
});
var config = {
map: map,
packages: packages
};
System.config(config);
})(this);
This is the config file I've used to set up SystemJS. 这是我用来设置SystemJS的配置文件。 However,
rxjs
and @angular
aren't being pulled in by SystemJS. 然而,
rxjs
和@angular
不被SystemJS拉入。 The errors are gone from the console in the browser, but the app is definitely not being bootstrapped. 错误已从浏览器的控制台中消失,但该应用程序绝对未启动。
Is there any other way to get the @angular
files to be pulled in by SystemJS? 还有其他方法可以让
@angular
文件由SystemJS提取吗? What other options do I have to get an Angular 2 app up and running with Sails? 要启动Angular 2应用并在Sails中运行,我还需要其他哪些选择?
**** EDIT **** **** 编辑 ****
Here is a gist with the systemjs.config.js
file, the layout.ejs
file, and the main.ts
file. 这是一个包含
systemjs.config.js
文件, layout.ejs
文件和main.ts
文件的main.ts
。
I got my app to start loading the @angular
packages like it was supposed to. 我让我的应用开始像预期的那样开始加载
@angular
软件包。 I'm not sure why this was an issue, but it turned out to affect me. 我不确定为什么这是一个问题,但事实证明会影响到我。 In my
tsconfig.json
file, I had an outFile
attribute declared. 在我的
tsconfig.json
文件中,我声明了outFile
属性。 I made sure that the file was transpiled and output to the right spot, but it didn't work until I removed the outFile
attribute and let it determine that part on its own. 我确保文件已被编译并输出到正确的位置,但是直到我删除了
outFile
属性并让它自己确定该部分后,该文件才起作用。
This may not be the answer to everyone's issue, but it worked for me. 这可能无法解决每个人的问题,但是对我有用。
Best way to make sails/angular application is to to do it by REST API based architecture. 制作帆/角度应用程序的最佳方法是通过基于REST API的体系结构来实现。 You remove views from sails and create REST APIs for standalone Angular2 application.
您可以从视图中删除视图,并为独立的Angular2应用程序创建REST API。 Then you use angular 2 material in Angular2.
然后,在Angular2中使用angular 2材质。 This way you will have least of problems.
这样,您将几乎没有问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.