我试图为另一个SO问题创建一个演示,首先是angular-cli,然后是punker.
我import在两个版本之间遇到了奇怪的行为差异.
问题import出现在以下代码中的第二个:
moment.service.ts
import { Injectable } from '@angular/core';
// Following work in plunker setup
import m from 'moment';
// Following work in angular-cli setup
//import * as m from 'moment';
@Injectable()
export class MomentService {
moment = m;
}
Run Code Online (Sandbox Code Playgroud)
在angular-cli代码中,我必须使用:
import * as m from 'moment';
Run Code Online (Sandbox Code Playgroud)
如果我使用punker设置,无论是在punker中还是在运行本地服务器,我必须关注或者它不会在浏览器中运行:
import m from 'moment';
Run Code Online (Sandbox Code Playgroud)
任何人都可以解释行为的差异?
Plunker:链接
Github:plunker代码本地版本(包括一个本地服务的server.js)
Github:angular-cli版本
所以我的应用程序基于角度2(角度cli)和一些CMS.页面的某些片段从CMS下载并显示在角度2页面上.主要问题是页眉和页脚来自CMS.所以我想知道如何添加全局解析器(全局非常重要,我不想为应用程序中的每个路径路径添加解析器),这将强制角度等待CMS返回页眉和页脚.我已经成功使用解析器通过实现路由接口等待某些路由上的某些数据
export class InboxResolver implements Resolve<MessageListItem[]>
Run Code Online (Sandbox Code Playgroud)
我在一些自定义路线中使用它:
const MessagesRoutes: Routes = [
{
path: 'inbox',
component: InboxComponent,
resolve: { messages: InboxResolver }
}
];
Run Code Online (Sandbox Code Playgroud)
但是如何在一个地方定义一个全局HeaderAndFooterResolver?
我有angular 2应用程序(使用了cli cli)。我想为该应用程序构建Web和移动(cordova)版本。
所以我想ng build -e prod用于生产和ng build -e cordova --output-path mobile/www --base-href ./科尔多瓦项目。
<script type="text/javascript" src="cordova.js"></script>如果环境是Cordova,则要包含;如果环境是生产环境,则要排除Facebook Web API脚本,反之亦然
我npm install -g angular-cli在MacOS上运行时遇到此错误:
npm ERR! node v6.9.2
npm ERR! npm v3.10.9
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! at Error (native)
npm ERR! { Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! at Error (native)
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib/node_modules' }
npm ERR!
npm ERR! Please try …Run Code Online (Sandbox Code Playgroud) 我有一个现有的Durandal应用程序,实际上是两个应用程序纠缠在一起.
我想重写Angular中的应用程序,并希望区分应用程序共享公共代码.
我估计大约80%的代码可以共享.
如果可能的话,我想使用angular-cli.但我真的在寻找如何在Angular应用程序之间共享代码的最佳实践.
@ angular / cli @ 1.0.0-rc.2
ng build -prod -e prod
vendor.380a744….bundle.js:218 Error: Runtime compiler is not loaded
at new Error (native)
at Error.d (http://localhost:9000/portal/assets/dist/polyfills.a61f849adcea6ec74b69.bundle.js:36:1731)
at r (http://localhost:9000/portal/assets/dist/vendor.380a74466a8bf08fbdda.bundle.js:1410:3338)
at t.compileModuleAndAllComponentsAsync (http://localhost:9000/portal/assets/dist/vendor.380a74466a8bf08fbdda.bundle.js:1417:702)
at e.ngOnChanges (http://localhost:9000/portal/assets/dist/main.f4b767a4fe115c7bb97e.bundle.js:1:1171229)
at e.ngDoCheck (http://localhost:9000/portal/assets/dist/main.f4b767a4fe115c7bb97e.bundle.js:1:914180)
at t.GGjx.t.detectChangesInternal (http://localhost:9000/portal/assets/dist/main.f4b767a4fe115c7bb97e.bundle.js:1:332790)
at t.R2h3.t.detectChanges (http://localhost:9000/portal/assets/dist/vendor.380a74466a8bf08fbdda.bundle.js:653:5749)
at t.Sqya.t.detectChangesInNestedViews (http://localhost:9000/portal/assets/dist/vendor.380a74466a8bf08fbdda.bundle.js:667:780)
at t.GGjx.t.detectChangesInternal (http://localhost:9000/portal/assets/dist/main.f4b767a4fe115c7bb97e.bundle.js:1:329907)
at t.R2h3.t.detectChanges (http://localhost:9000/portal/assets/dist/vendor.380a74466a8bf08fbdda.bundle.js:653:5749)
at t.R2h3.t.internalDetectChanges (http://localhost:9000/portal/assets/dist/vendor.380a74466a8bf08fbdda.bundle.js:653:5542)
at t.YSmj.t.detectChangesInternal (http://localhost:9000/portal/assets/dist/main.f4b767a4fe115c7bb97e.bundle.js:1:662563)
at t.R2h3.t.detectChanges (http://localhost:9000/portal/assets/dist/vendor.380a74466a8bf08fbdda.bundle.js:653:5749)
at t.Sqya.t.detectChangesInNestedViews (http://localhost:9000/portal/assets/dist/vendor.380a74466a8bf08fbdda.bundle.js:667:780)
Run Code Online (Sandbox Code Playgroud)
package.json
{
"name": "app",
"version": "1.0.0",
"description": "Origianlly fomr a webpack starter for …Run Code Online (Sandbox Code Playgroud) 最近我的应用程序从Angular 2.3.0升级到Angular 4.0.3.在此过程中还升级了angular-cli.如果项目克隆到新目录,则抛出:
无法读取属性'config'的null TypeError:无法在Class.run中读取null的属性'config'(/Users/hyadav/Documents/projects/web-app/node_modules/@angular/cli/tasks/build.js:16 :56)在Class.run(/Users/hyadav/Documents/projects/web-app/node_modules/@angular/cli/commands/build.js:143:26)上课.(/Users/hyadav/Documents/projects/web-app/node_modules/@angular/cli/ember-cli/lib/models/command.js:134:17)at process._tickCallback(internal/process/next_tick.js: 109:7)
的package.json
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^4.0.3",
"@angular/cli": "^1.0.1",
"@angular/common": "^4.0.3",
"@angular/compiler": "^4.0.3",
"@angular/compiler-cli": "^4.0.3",
"@angular/core": "^4.0.3",
"@angular/forms": "^4.0.3",
"@angular/http": "^4.0.3",
"@angular/material": "^2.0.0-beta.3",
"@angular/platform-browser": "^4.0.3",
"@angular/platform-browser-dynamic": "^4.0.3",
"@angular/platform-server": "^4.0.3",
"@angular/router": "^4.0.3",
"core-js": "^2.4.1",
"hammerjs": "^2.0.8",
"rxjs": "^5.2.0",
"typescript": "^2.2.2",
"zone.js": "^0.8.4"
},
"devDependencies": {
"@angular/cli": "^1.0.1",
"@angular/compiler-cli": "^2.4.0",
"@types/jasmine": "2.5.38",
"@types/node": "~6.0.60", …Run Code Online (Sandbox Code Playgroud) 这段代码中有一个错误
<img src="../../../assets/gms-logo.png" alt="logo" routerLink="/overview" alt="website icon">
Run Code Online (Sandbox Code Playgroud)
但是当我检查资产文件夹时,gms-logo.png仍然存在angular-cli.json,资产也存在.路径也是正确的.
最近,我一直在研究搜索功能.所以我的假设是,
即使用户仍未关注输入类型,程序是否也开始搜索?我该如何解决?
下面是我的搜索html以及其建议段的显示
<input type="text" placeholder="Search" (keyup)="onSearch($event.target.value)">
<div class="suggestion" *ngIf="results.length > 0">
<div *ngFor="let result of results ">
<a href="" target="_blank">
{{ result.name }}
</a>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
以下是我的组件
results: Object;
onSearch(name) {
this.search
.searchEmployee(name)
.subscribe(
name => this.results = name,//alert(searchName),this.route.navigate(['/information/employees/']),
error => alert(error),
);
}
Run Code Online (Sandbox Code Playgroud) typeerror google-developer-tools angular-cli google-developers-console angular
如何从Angular 4项目的github中排除环境文件。
我已经将.gitignore更新为以下内容,但是我的环境文件仍在同步到github:/ src / environments / **
# See http://help.github.com/ignore-files/ for more about ignoring files.
# compiled output
/dist
/tmp
/out-tsc
# dependencies
/node_modules
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
# misc
/.sass-cache
/connect.lock
/coverage
/libpeerconnection.log
npm-debug.log
testem.log
/typings
/src/environments/**
# e2e
/e2e/*.js
/e2e/*.map
# System Files
.DS_Store
Thumbs.db
Run Code Online (Sandbox Code Playgroud) 我在使用Angular CLI创建新组件时遇到了一个奇怪的错误,当我使用ng g c navbar它时抛出错误:
core_1.PriorityQueue is not a constructor
TypeError: core_1.PriorityQueue is not a constructor
at new TaskScheduler (/home/praveen/Desktop/Angular_Projects/a2website/node_modules/@angular-devkit/schematics/src/engine/task.js:20:23)
at SchematicEngine.createContext (/home/praveen/Desktop/Angular_Projects/a2website/node_modules/@angular-devkit/schematics/src/engine/engine.js:81:31)
at SchematicImpl.call (/home/praveen/Desktop/Angular_Projects/a2website/node_modules/@angular-devkit/schematics/src/engine/schematic.js:35:38)
at Promise (/home/praveen/Desktop/Angular_Projects/a2website/node_modules/@angular/cli/tasks/schematic-run.js:73:23)
at new Promise (<anonymous>)
at Class.run (/home/praveen/Desktop/Angular_Projects/a2website/node_modules/@angular/cli/tasks/schematic-run.js:72:16)
at Class.run (/home/praveen/Desktop/Angular_Projects/a2website/node_modules/@angular/cli/commands/generate.js:161:33)
at resolve (/home/praveen/Desktop/Angular_Projects/a2website/node_modules/@angular/cli/ember-cli/lib/models/command.js:261:20)
at new Promise (<anonymous>)
at Class.validateAndRun (/home/praveen/Desktop/Angular_Projects/a2website/node_modules/@angular/cli/ember-cli/lib/models/command.js:240:12)
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助我吗?.提前谢谢.
angular-cli ×10
angular ×8
code-sharing ×1
cordova ×1
git ×1
github ×1
javascript ×1
npm ×1
npm-install ×1
resolver ×1
systemjs ×1
typeerror ×1
typescript ×1
webpack ×1