我有一个数组列表,看起来像:
[new Class1(), new Class2(), new Class1(), new Class1()]
Run Code Online (Sandbox Code Playgroud)
我想知道在数组列表中提取Class1实例数的最有效方法.
对于上面的例子,我想要答案3.
我使用的是Java版"1.7.0_79".
我正在使用 Angular 5。
热重载大约需要 8 秒,这是合理的(虽然不是很好)但是有什么方法可以配置它以便我可以调整它以使其更快?
担心随着应用程序的增长它会变得更慢。谢谢。
我有一个 Observable(我们称之为 myob$),它发出这样的值:
----- 空 ----- 1 ----------- 5 ---->
如果我做:
myob$.subscribe(x => console.log(x))
输出是 ----- null ----- 1 ----------- 5 ---->
我可以添加一个管道,以便它在 myob$ 的值不为空之前不会发出吗?
就像是:
myob$.pipe(x => ignoreEverytingUntilXIsNotNull).subscribe(x => console.log(x))
所以输出是 --------------- 1 ----------- 5 ---->
提前致谢
我在我的应用程序中包含了一个 Bootstrap 主题。我已将文件复制到 src 文件夹(与 style.css 相同级别)并将其添加为 angular.json 中的最后一个 css,如下所示:
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/WFRH-Web",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets",
"src/web.config"
],
"styles": [
"src/styles.css",
"node_modules/bootstrap/dist/css/bootstrap.min.css",
"node_modules/bootstrap-select/dist/css/bootstrap-select.min.css",
"src/theme_minco.min.css"
Run Code Online (Sandbox Code Playgroud)
并且样式在开发模式下正常工作,但在部署我的应用程序后它们不起作用。
我用于部署的步骤是:
1) ng build --prod
2) firebase deploy
Run Code Online (Sandbox Code Playgroud)
我也试过在styles.css中使用include,只在angular.json中保留styles.css,如下所示:
@import "theme_minco.min.css";
Run Code Online (Sandbox Code Playgroud)
无济于事,因为它也不起作用(它仅适用于开发人员)。
请问有什么帮助吗?
我的 Angular 应用程序的服务中有以下代码:
const subby = Subject.create(observer, observable)
Run Code Online (Sandbox Code Playgroud)
但我的 IDE 正确标记Subject.create为已弃用。我应该用什么代替谢谢?我尝试过new Subject(observer, observable),但没有快乐。TIA。
RxJS版本:6.4.0
角度版本:7.2
我正在尝试根据关闭或打开 mat-sidenav 更改 mat-icon 的图标,但无法找到 sidenav 是否打开或关闭,下面是我的代码
<mat-sidenav appResponsiveMenu mode="side" opened>
my menu items list
</mat-sidenav>
Run Code Online (Sandbox Code Playgroud)
这是切换按钮
<button mat-icon-button (click)="sidenav.toggle()">
<mat-icon *ngIf="sidenav">keyboard_arrow_left</mat-icon>
<mat-icon *ngIf="!sidenav">keyboard_arrow_right</mat-icon>
</button>
Run Code Online (Sandbox Code Playgroud)
.ts 代码
@ViewChild(MatSidenav)
sidenav!: MatSidenav;
Run Code Online (Sandbox Code Playgroud) 我正在学习Angular2,现在正尝试使用Karma进行一些单元测试.
我根据这篇文章https://dimakuzmich.wordpress.com/2015/08/21/test-angular2-now-or-how-to-set-up-angular2-unit-tests/配置了我的项目,但是当我跑步时单元测试我得到以下错误:
WARN [web-server]: 404: /base/src/angular2/angular2
Error: XHR error (404 Not Found) loading http://localhost:9876/base/src/angular2/angular2
我有gulp任务,将我的ts文件编译成JavaScript.
karma.conf.js
module.exports = function (config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
// list of files / patterns to load in the browser
files: [
'node_modules/traceur/bin/traceur-runtime.js',
{ pattern: 'src/build/**/*.js', included: false, …Run Code Online (Sandbox Code Playgroud) 我知道全局变量很糟糕,但我想用一个.
摘自package.json:
"scripts": {
"start": "nodemon jobsServer.js",
"test": "cross-env NODE_ENV=test ./node_modules/.bin/istanbul cover -x \"**/*.spec.js\" ./node_modules/mocha/bin/_mocha -- jobs js --recursive -R spec"
},
Run Code Online (Sandbox Code Playgroud)
jobsServer.js:
global.appPath = require('app-root-path');
// more code here
Run Code Online (Sandbox Code Playgroud)
现在我希望能够在应用程序的任何位置访问appPath.
当我运行npm start它时,它会选择全局变量,我很高兴.
但是当我运行npm test它时不会加载全局(因为全局是在服务器文件中定义的),因此对appPath的所有引用都会中断.
我不想做:
const appPath = require('app-root-path');
Run Code Online (Sandbox Code Playgroud)
在每个单独的.spec.js测试文件中.
如何为每个spec文件加载全局变量?
我尝试过各种 SMTP 服务器,但我无法让 Jenkins 发送电子邮件。我收到could not connect错误 - 没有别的,只是这个错误。
请参阅下面的屏幕截图。
任何想法为什么?我正在使用 Jenkins docker 容器,防火墙关闭。
我没有在 Jenkins 容器内运行电子邮件服务器。我想如果 Gmail 会为我发送电子邮件,我不需要它。
我们的 ngrx Angular 应用程序运行良好,直到我们卸载 Redux Devtools,此时我们会收到错误:
您在需要流的地方提供了无效的对象。您可以提供 Observable、Promise、Array 或 Iterable。
app.module.ts 中的商店设置如下所示:
StoreModule.forRoot(reducers, {metaReducers}),
!environment.production ? StoreDevtoolsModule.instrument() : [],
EffectsModule.forRoot([SimsEffects, FiltersEffects, OmnipresentEffects, UserEffects, InitEffects]),
StoreRouterConnectingModule.forRoot({stateKey: 'router'})
Run Code Online (Sandbox Code Playgroud)
我们的 ngrx reducers/index.ts 文件如下所示:
export interface AppState {
router: any,
omnipresent: OmnipresentState,
user: UserState
}
export const reducers: ActionReducerMap<AppState> = {
router: routerReducer,
omnipresent: omnipresentReducer,
user: userReducer
}
export function resetStore(reducer) {
return (state, action) => {
return reducer(action.type === InitActionTypes.ResetStore ? undefined : state, action)
}
}
// storeFreeze throws an error early …Run Code Online (Sandbox Code Playgroud) angular ×6
rxjs ×2
angular-cli ×1
angular-ui ×1
css ×1
deployment ×1
hot-reload ×1
java ×1
java-7 ×1
javascript ×1
jenkins ×1
karma-runner ×1
livereload ×1
mocha.js ×1
ngrx ×1
node.js ×1
smtp ×1
typescript ×1
unit-testing ×1