我使用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就是这样一个雷区.
你有没有处理类似的问题?
我最近读到有关 C# 8.0 具有接口默认实现的信息,所以我进入了我的项目并尝试了它,但我遇到了一个错误。Target runtime doesn't support default interface implementation. 有没有办法解决这个问题?
string CommandName { get => CommandName.ToUpperInvariant(); }
Run Code Online (Sandbox Code Playgroud)
编辑
我正在使用Console
我是TypeScript和Visual Studio Code的新手.我收到以下错误:
*[ts] Property 'payload' does not exist on type 'Actions'.
我的代码:
action.ts文件:
import { Action } from '@ngrx/store';
import { Item } from '../models/list';
export class AddBookAction implements Action {
type = ActionTypes.ADD_BOOK;
constructor(public payload: Item) { }
}
export type Actions = AddBookAction;
Run Code Online (Sandbox Code Playgroud)
reducer.ts
import * as list from 'action';
export function reducer(state = initialState, action: list.Actions): State {
switch (action.type) {
case list.ActionTypes.LOAD: {
return Object.assign({}, state, {
loading: true
});
}
case list.ActionTypes.LOAD_SUCCESS: {
const …Run Code Online (Sandbox Code Playgroud) 我这里有一个严重的问题。我的应用程序依赖于 SignalR 功能,但因此我无法编写单元测试。我是测试框架的新手,只在简单的情况下使用过 Jasmine。事实证明 SignalR 对我来说是一个太大的挑战,但我需要了解如何成功测试它。这是我的 CommsApp.ts 文件 [打字稿]:
/// <reference path="References.ts" />
var commsAnimationsModule = angular.module('forge.communications.animations', ['ngAnimate']);
var commsDirectivesModule = angular.module('forge.communications.directives', []);
var commsServicesModule = angular.module('forge.communications.services', []);
var commsFiltersModule = angular.module('forge.communications.filters', []);
var commsApp = angular.module('forge.communications.CommsApp',
[
'ngRoute',
'ngAnimate',
'cfValidation',
'ui.bootstrap',
'forge.communications.animations',
'forge.communications.directives',
'forge.communications.services',
'forge.communications.filters',
'angularFileUpload',
'timeRelative'
]);
commsApp.config(function ($routeProvider: ng.route.IRouteProvider, $locationProvider: any) {
$locationProvider.html5Mode(true);
$routeProvider.
when('/scheduled-messages', {
templateUrl: '/forge/CommsApp/js/Controllers/ScheduledMessageList/ScheduledMessageList.html',
controller: 'ScheduledMessageListController'
}).
when('/geotriggered-messages', {
templateUrl: '/forge/CommsApp/js/Controllers/GeoMessageList/GeoMessageList.html',
controller: 'GeoMessageListController'
}).
when('/scheduled-message/create', {
templateUrl: '/forge/CommsApp/js/Controllers/CreateScheduledMessage/CreateScheduledMessage.html',
controller: 'CreateScheduledMessageController'
}).
when('/scheduled-message/edit/:id', { …Run Code Online (Sandbox Code Playgroud) 我想在Angular Material Datepicker组件中禁用周末和特定日期。
我怎样才能做到这一点?
app.component.html:
<mat-form-field>
<input matInput [matDatepicker]="picker" placeholder="Choose a date">
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker></mat-datepicker>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)
package.json:
"dependencies": {
"@angular/animations": "^5.1.3",
"@angular/cdk": "^5.0.3",
"@angular/common": "^5.0.0",
"@angular/compiler": "^5.0.0",
"@angular/core": "^5.0.0",
"@angular/forms": "^5.0.0",
"@angular/http": "^5.0.0",
"@angular/material": "^5.0.3",
"@angular/platform-browser": "^5.0.0",
"@angular/platform-browser-dynamic": "^5.0.0",
"@angular/router": "^5.0.0",
"core-js": "^2.4.1",
"rxjs": "^5.5.2",
"zone.js": "^0.8.14"
},
Run Code Online (Sandbox Code Playgroud) 当我使用ngxs我的应用程序应该做什么时:
在 Ubuntu 16.04 上创建解决方案文件时,JetBrains Rider 无限期挂起。已经重新启动了 Rider 和我的系统。
我正在使用 NgRx ^7.0.0 版本。这是我的 NgRx 效果类:
import { Injectable } from '@angular/core';
import { ApisService } from '../apis.service';
import { Effect, Actions, ofType } from '@ngrx/effects';
import { Observable } from 'rxjs';
import { ApisActionTypes, ApisFetched } from './apis.actions';
import { mergeMap, map } from 'rxjs/operators';
@Injectable()
export class ApisEffects {
constructor(private apisS: ApisService, private actions$: Actions) { }
@Effect()
$fetchApisPaths: Observable<any> = this.actions$.pipe(
ofType(ApisActionTypes.FetchApisPaths),
mergeMap(() =>
this.apisS.fetchHardCodedAPIPaths().pipe(
map(res => new ApisFetched(res))
)
)
);
}
Run Code Online (Sandbox Code Playgroud)
这是一个简单的测试。如您所见,它应该失败,但总是通过。我在 StackOverflow 上遵循了类似的问题如何对这种效果进行单元测试(使用 …
从Jest注意:注意:默认情况下,jest.spyOn也调用spied方法。
在我的Angular组件中。
ngAfterViewInit(): void {
this.offsetPopoverPosition();
}
Run Code Online (Sandbox Code Playgroud)
在我的规格中:
it('ngAfterViewInit() method should call offsetPopoverPosition() method', () => {
const mockListener = jest.spyOn(cmp, 'offsetPopoverPosition');
const spy = mockListener.mockImplementation(() => {
console.log('in the mock');
});
cmp.ngAfterViewInit();
expect(spy).toHaveBeenCalled();
});
Run Code Online (Sandbox Code Playgroud)
简单。然而,原始功能仍在被调用。我检查了Jest 23.x文档:https : //jestjs.io/docs/en/23.x/jest-object#jestspyonobject-methodname https://jestjs.io/docs/en/23.x/mock-function -api#mockfnmockimplementationfn
互联网上的例子很少,但我无法阻止开玩笑地调用原始offsetPopoverPosition()方法。
有任何想法吗?
我交叉链接到Jest github问题,由于某种原因该问题未解决而已关闭。
angular ×5
javascript ×3
jestjs ×2
ngrx ×2
unit-testing ×2
angular-cli ×1
angularjs ×1
c# ×1
c#-8.0 ×1
interface ×1
istanbul ×1
jquery ×1
ngrx-effects ×1
ngxs ×1
redux ×1
rider ×1
signalr ×1
typescript ×1
ubuntu-16.04 ×1
webpack ×1