大佬教程收集整理的这篇文章主要介绍了npm – Angular2 beta – 自举HTTP_PROVIDERS – “意外令牌<”,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这是一个dumbed down版本,显示了我有的问题。首先在这里一个Hello世界的应用程序完美工作。
package.json
{ "name": "...","version": "0.0.1","description": "...","author": { "name": "...","email": "..." },"scripts": { "tsc": "tsc","tsc:w": "tsc -w","lite": "lite-server","start": "concurrent \"npm run tsc:w\" \"npm run lite\" " },"license": "ISC","dependencies": { "angular2": "2.0.0-beta.0","bootstrap": "^3.3.6","es6-promise": "^3.0.2","es6-shim": "^0.33.3","reflect-Metadata": "^0.1.2","rxjs": "5.0.0-beta.0","systemjs": "0.19.6","zone.js": "^0.5.10" },"devDependencies": { "concurrently": "^1.0.0","lite-server": "^1.3.1","typescript": "^1.7.3" } }
index.html
<head> <title>title</title> <link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.min.css"> <link href="styles.css" rel="stylesheet" /> <!-- 1. Load libraries --> <script src="node_modules/es6-shim/es6-shim.js"></script> <script src="node_modules/angular2/bundles/angular2-polyfills.js"> </script> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="node_modules/rxjs/bundles/Rx.js"></script> <script src="node_modules/angular2/bundles/angular2.dev.js"></script> <!-- 2. Configure SystemJS --> <script> System.config({ packages: { app: { format: 'register',defaultExtension: 'js' } } }); System.import('app/boot') .then(null,console.error.bind(consolE)); </script> </head> <!-- 3. Display the application --> <body> <my-app></my-app> </body>
app / boot.ts
import {Bootstrap} from 'angular2/platform/browser' import {AppComponent} from './app.component' import {Account@R_616_9260@cE} from './accounts/account.@R_616_9260@ce' bootstrap(AppComponent);
app / app.component.ts
import {Component,View} from 'angular2/core'; import {RegisterFormComponent} from './accounts/register-form.component' @Component({ SELEctor: 'my-app',}) @View({ template: 'Hello world',}) export class AppComponent { }
我真的想调用我的Web Api服务,所以我试图关注the docs for Http,我更新boot.ts如下:
新应用程序/ boot.ts
import {Bootstrap} from 'angular2/platform/browser' import {AppComponent} from './app.component' import {Account@R_616_9260@cE} from './accounts/account.@R_616_9260@ce' import {http_PROVIDERS} from 'angular2/http'; bootstrap(AppComponent,[http_PROVIDERS]);
这里是东西窒息的地方。
Chrome给了我:
uncaught SyntaxError: Unexpected token < - http:1 uncaught SyntaxError: Unexpected token < - angular2-polyfills.js:138 evaluaTing http://localhost:3000/angular2/http error loading http://localhost:3000/app/boot.js
如果我尝试将http_PROVIDERS设置为我的组件上的viewProvider,它也会失败。
有没有人有任何运气得到http注入正确在angular2 beta?
> Visual studio 2015
> Node.JS& Node.JS工具的视觉工作室
>使用“NPM start”编译和运行
<script src="https://code.angularjs.org/2.0.0-beta.0/http.dev.js"></script>
尝试使用路由器时,您会看到此相同的错误,并且忘记添加路由器包。
检查这两个配置之间的区别从@ pkozlowski-opensource的回购
> Using SystemJS:对于这种情况,他将不得不添加Http包或路由器包,如果他想使用它们。
> Using Webpack:在这种情况下,Webpack会捆绑bundle.js文件中的所有内容。
很高兴它帮助。
以上是大佬教程为你收集整理的npm – Angular2 beta – 自举HTTP_PROVIDERS – “意外令牌<”全部内容,希望文章能够帮你解决npm – Angular2 beta – 自举HTTP_PROVIDERS – “意外令牌<”所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。