我用angular 2移动我的第一步,特别是我使用angular-cli官方工具来创建新项目.
我以这种方式创建了一个新项目
ng new [my-project-name]
Run Code Online (Sandbox Code Playgroud)
该项目是正确创建的.
之后我想安装bootstrap 4,然后按照angular-cli页面中的官方指南进行操作.
我用npm安装bootstrap:
npm install bootstrap@next
Run Code Online (Sandbox Code Playgroud)
我在angular-cli.json中添加了这一行:
"scripts": [
"../node_modules/jquery/dist/jquery.js",
"../node_modules/tether/dist/js/tether.js",
"../node_modules/bootstrap/dist/js/bootstrap.js"
],
"styles": [
"styles.css",
"../node_modules/bootstrap/dist/css/bootstrap.css"
],
Run Code Online (Sandbox Code Playgroud)
在app对象中.
当我构建应用程序并在服务器中运行它: ng serve
我没有在index.html中找到bootstrap css和javascript的参考.
我不明白是否在我的index.html中自动添加了此文件的导入,或者我需要手动添加它.
我使用Angular-CLI创建了一个应用程序,并且出于调试目的,希望在应用程序中显示有关正在运行的构建的一些信息.例如,git分支或构建时间等.
我可以编写一个操作的脚本,src/environments/environment.ts但我问自己是否有更好的方法.特别是因为该文件是源代码控制的一部分.
在Angular-CLI上切换以覆盖变量的值会很好.让我们说变量environment.build并environment.time设置为dummys in environment.ts.然后ng --env[build]=master --env[time]=201612130742我会用计算值覆盖那些.
但据我所知,这样的东西不存在?
我使用最新版本的Angular-CLI来创建Angular2项目.我在src/assets/styles/_vars.scss中有一个包含变量的sass文件.是否可以配置sass编译器,所以我只需要编写
@import "vars";
Run Code Online (Sandbox Code Playgroud)
而不是写出完整的路径或相对路径?
我对angular-cli有一点疑问.
这是真的,当我运行NG服务我用的是全球安装角CLI当我运行NPM开始的地方吗?
我决定对angular-cli使用扩展的webpack配置,所以我运行命令ng eject.
看起来除了环境文件替换之外,一切都正常工作,在angular-cli.json中指定:
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
Run Code Online (Sandbox Code Playgroud)
现在根本没有替换,它总是使用"environments/environment.ts"文件.
有没有办法让它在没有重大更改webpack配置的情况下工作?
还为angular-cli github项目创建了一个问题.
我使用angular-cli引导了Angular 2应用程序.在我决定使用bootstrap模态之前,一切都很容易.我只是复制了从不使用angular-cli的其他项目中打开模态的代码.我将jquery和bootstrap依赖项添加到angular-cli.json文件中的脚本中.jQuery在项目中被识别,但是当我尝试this.$modalEl.modal(options)在角度组件内运行时,我得到一个错误jQuery is not defined.
实际上jQuery被导入到项目中但作为全局$.我做了一些挖掘,显然bootstrap期望jQuery作为'jQuery'变量传递给它.它没有给老鼠的屁股$.
我可以像在其他项目中一样jQuery在webpack.config.js文件中公开变量:(为简洁起见省略了很多代码)
var jQueryPlugin = {
$: 'jquery',
jquery: 'jquery',
jQuery: 'jquery'
}
exports.root = root;
exports.plugins = {
globalLibProvider: new webpack.ProvidePlugin(webpackMerge(jQueryPlugin, {
svg4everybody: 'svg4everybody/dist/svg4everybody.js'
}))
}
Run Code Online (Sandbox Code Playgroud)
但angular-cli开发团队决定不让其他开发者干涉webpack配置文件.多谢你们!非常考虑你.
我已经尝试将jQuery直接导入到Angular组件中,并在这里提到了一些其他的东西https://github.com/angular/angular-cli/issues/3202(将进口添加到vendor.ts文件然后添加vendor.ts到angular-cli.json中的scripts数组但没有任何效果.
说实话,我很生气这样一个微不足道的问题,比如在angular-cli中增加jquery依赖性bootstrap就是这样一个雷区.
你有没有处理类似的问题?
不久,我有一个应用程序,在服务上是4.6MB.
当我做:
ng serve --prod
我得到1MB的文件大小.
但是,--prod以某种方式使我的整个应用程序中断.
我向服务器发送请求的整个服务(基于承诺)不再有效.
bizzar的事情是,只要没有服务器请求,简单的ng服务工作完全正常和ng服务的某些部分--prod工作正常.
我没有发布任何代码,因为ng服务版本工作正常.
主要问题是:
为什么我会采取帽子行为?
此外,在某些时候,基于ng服务的应用程序--prod突然完全无处不在,然后我重新启动应用程序,再次,一个破碎的应用程序.
编辑: 更多EXPLICIT细节:
我正在使用Fiddler确保所有细节都正确无误:
如您所见,细节还可以.
现在负责在客户端模拟该请求的代码:
login(uName: string, pw: string, type: number): Promise<any> {
return new Promise(resolve => {
if (type === 1) {
const options = new RequestOptions({ headers: this.headers });
const body = JSON.stringify({ username: uName, password: pw });
this.http.post(this.loginUrl, body, options)
.toPromise()
.then(response => {
resolve(response);
})
.catch(this.handleError);
} else if (type …Run Code Online (Sandbox Code Playgroud) 我正在按照本教程关于如何将angular与firebase数据库连接起来.但是在第17:30分钟,我收到了这个错误:
'AngularFireList <{}>'类型中不存在属性'subscribe'
我的AppComponent:
import { Component } from '@angular/core';
import {AngularFireDatabase, AngularFireDatabaseModule} from 'angularfire2/database';
import {AngularFireAuth, AngularFireAuthModule} from 'angularfire2/auth';
import { Observable } from 'rxjs/Observable';
import * as firebase from 'firebase/app';
import { Country } from './models/country';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
countries: any[];
constructor(db: AngularFireDatabase )
{
db.list('/Country/countries')
.subscribe(countries => { // <--ERROR IS HERE
this.countries = countries;
console.log(this.countries);
});
}
}
Run Code Online (Sandbox Code Playgroud)
我的模特:
export class Country {
// --ATTRIB-- …Run Code Online (Sandbox Code Playgroud) firebase firebase-realtime-database angular-cli angularfire2
我正在尝试将此(ngx-admin)免费的Angular模板升级到Angular 5,然后尝试在此SO Post中提到的WebWorker中运行整个应用程序.
我成功将应用程序升级到Angular 5并且工作正常但是当我尝试将应用程序配置为在Webworker中运行时,它会出现以下错误:
完整的代码(修改为Angular 5和webworker)可以在这里找到
我试图在我的webpack配置中添加DefinePlugin,但没有运气.
webpack.config.json:
new DefinePlugin({
window: undefined,
document: undefined
}),
Run Code Online (Sandbox Code Playgroud)
我能够在webworker中运行新的空angular-cli应用程序,但我无法在webworker中运行此模板.我想有一些节点包正在创建问题.
的package.json:
{
"scripts": {
"ng": "ng",
"conventional-changelog": "conventional-changelog",
"e2e": "protractor ./protractor.conf.js",
"docs": "compodoc -p src/tsconfig.app.json -d docs",
"docs:serve": "compodoc -p src/tsconfig.app.json -d docs -s",
"release:changelog": "npm run conventional-changelog -- -p angular -i CHANGELOG.md -s",
"build": "webpack",
"start": "webpack-dev-server --port=4200",
"test": "karma start ./karma.conf.js",
"pree2e": "webdriver-manager update --standalone false --gecko false --quiet"
},
"dependencies": {
"@agm/core": "1.0.0-beta.2",
"@angular/animations": …Run Code Online (Sandbox Code Playgroud) 我更新了我的angular-cli然后我在ng服务中出错了
Callback was already called.
at throwError (node_modules\neo-async\async.js:14:11)
at node_modules\neo-async\async.js:2805:7
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
Run Code Online (Sandbox Code Playgroud)
这是我的项目包的版本:
Angular CLI: 6.0.7
Node: 8.9.4
OS: win32 x64
Angular: 5.0.1
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.6.7
@angular-devkit/build-angular 0.6.7
@angular-devkit/build-optimizer 0.6.7
@angular-devkit/core 0.6.7
@angular-devkit/schematics 0.6.7
@angular/cdk 5.2.4
@angular/cli 6.0.7
@angular/material 5.2.4
@angular/platform-server 5.1.1
@ngtools/webpack 6.0.7
@schematics/angular 0.6.7
@schematics/update 0.6.7
rxjs 5.5.2
typescript 2.4.2
webpack 4.4.1
Run Code Online (Sandbox Code Playgroud)
我试图删除节点模块然后重新安装但仍然有相同的错误...任何建议?
angular-cli ×10
angular ×7
webpack ×5
angular5 ×2
javascript ×2
angularfire2 ×1
bootstrap-4 ×1
firebase ×1
jquery ×1
npm ×1
sass ×1
typescript ×1