当我在angular2-meteor项目中使用Collection2时,来自demo的这些代码总是在终端中给我警告:
返回表达式中不存在最常见的类型.
我该如何改进代码?谢谢
{
createdAt: {
type: Date,
autoValue: function() {
if (this.isInsert) {
return new Date();
} else if (this.isUpsert) {
return {$setOnInsert: new Date()};
} else {
this.unset();
}
}
}
}
Run Code Online (Sandbox Code Playgroud) meteor typescript meteor-collection2 angular2-meteor angular
我得到一个错误使用时angular2无限滚动.我想在一个plunkr中重现它.
我尝试使用npmcdn,所以我在index.html文件中添加了这一行:
<script src="https://npmcdn.com/angular2-infinite-scroll@0.1.2"></script>
Run Code Online (Sandbox Code Playgroud)
但是我得到了错误:
未捕获的ReferenceError:未定义require
这是我的傻瓜.
如何在plunker中正确添加NPM包?
我在TypeScript 2中使用Angular 2.
我用的时候
let labels: string[] | number[] = [];
// let labels: Array<number> | Array<string> = [];
labels.push(1);
Run Code Online (Sandbox Code Playgroud)
它给了我错误:
错误TS2349:无法调用其类型缺少调用签名的表达式.
我正在使用ngrx/effects.
我怎样才能发出空行动?
这就是我现在正在做的事情:
@Effect() foo$ = this.actions$
.ofType(Actions.FOO)
.withLatestFrom(this.store, (action, state) => ({ action, state }))
.map(({ action, state }) => {
if (state.foo.isCool) {
return { type: Actions.BAR };
} else {
return { type: 'NOT_EXIST' };
}
});
Run Code Online (Sandbox Code Playgroud)
由于我必须返回一个动作,我正在使用return { type: 'NOT_EXIST' };.
有一个更好的方法吗?
我正在使用ngrx/effects.
将rxjs从5.0.0-beta.12更新到5.0.0-rc.1之后,我的IDE WebStorm给出了下面的错误(红色下划线).当我运行我的应用程序时,同样的错误也会显示在终端中.
提供的参数与呼叫目标的任何签名都不匹配.
@Effect() updateProfile$ = this.actions$
.ofType(ProfileActions.PROFILE_UPDATE_PROFILE)
.map<string>(toPayload)
.switchMap(name => this.profileService.updateProfile(name)
.map(name => ({ type: ProfileActions.PROFILE_UPDATE_PROFILE_SUCCESS, payload: name }))
.catch(error => Observable.of({ type: ProfileActions.PROFILE_UPDATE_PROFILE_FAIL, payload: error }))
);
Run Code Online (Sandbox Code Playgroud)
.
updateProfile(name: string): Observable<string> {
return Observable.of(name);
}
Run Code Online (Sandbox Code Playgroud)
每当我使用时都会发生此错误map<string>(toPayload).我试图改变.map<any>(action => action.payload),但仍然是同样的错误.
效果map<string>(toPayload)不会给出错误.
虽然它给了我错误,但应用仍然运行良好.
如何解决这个问题?
我试图通过使用Meteor和Angular.js的组合来获取MongoDb中某个地址的警告
在我的html文件中,我正在做
<div ng-controller = "myController as myCtrl">
{{myCtrl.warnings}}
{{myCtrl.getWarnings("123 Test Street, TestCity, TestState")}}
</div>
Run Code Online (Sandbox Code Playgroud)
在我的app.js文件中:
Warnings = new Mongo.Collection("Warnings");
if (Meteor.isClient) {
var app = angular.module('ffprototype', [ 'angular-meteor' ]);
app.controller('myController', ['$window','$meteor', function($window, $meteor) {
this.warnings = $meteor.collection(Warnings);
this.getWarnings = function(findByAddress){
Warnings.find({address: findByAddress}).fetch();
}
}]);
}
Run Code Online (Sandbox Code Playgroud)
我的mongoDb集合:
{
"_id": "3ixgxEMZDWGtugxA7",
"address": "123 Test Street, TestCity, TestState",
"warning": "Warning 1"
}
{
"_id": "HZH5FvCD5driBYSJz",
"address": "123 Test Street, TestCity, TestState",
"warning": "Warning 2"
}
Run Code Online (Sandbox Code Playgroud)
html网页的输出显示整个警告集合(感谢{{currentDispatch.warnings}},但没有显示任何内容{{currentDispatch.getWarnings("123 Test Street, TestCity, …
我有一个abc组件(页面的一部分).它有一个事件mouseup.
@Component({
selector: 'abc-component'
})
@View({
<div (mousedown)="mouseDown()" (mouseup)="mouseUp()"></div>
})
export class ScheduleComponent {
mouseDown(){
//doSomthing
}
mouseUp(){}
}
Run Code Online (Sandbox Code Playgroud)
但是mouseup事件只能在鼠标内部触发时触发<div>.如何在外面触发事件<div>?
我是否必须移动(mouseup)="mouseUp()"到app.ts然后使用类似@Output或service让app.ts知道的东西?还有其他方法吗?
谢谢
我正在使用Angular 2.
我想动态创建多个输入,然后提供通过使用[(ngModel)]="input1"或其他方式获取其值的方法:
我考虑过使用[hidden],但由于我不知道用户想要的确切输入数量,所以我询问了如何动态创建输入.
HTML
<button (click)="addInput()">Add Input</button>
Run Code Online (Sandbox Code Playgroud)
TS
addInput() {
// first time click, add <input type="text" [(ngModel)]="input1"/>
// second time click, add <input type="text" [(ngModel)]="input2"/>
// third time click, add <input type="text" [(ngModel)]="input3"/>
// forth, fifth, etc.
}
Run Code Online (Sandbox Code Playgroud)
谢谢
通常checked只在输入结束时添加
<input type="radio" name="item" value="value1" checked>
<input type="radio" name="item" value="value2">
Run Code Online (Sandbox Code Playgroud)
但现在我正在使用*ngFor.我想选择第一个.
我尝试这样做,但它不起作用,因为checked它不是一个类.
<div *ngFor="#item of collection; #i = index"">
<input type="radio" name="item" value="{{item}}" [ngClass]="{'checked':i === 0}">
<label>{{item}}</label>
</div>
Run Code Online (Sandbox Code Playgroud)
那我该怎么办呢?谢谢!
我在 React 中使用 video.js。我尝试迁移到 React Hooks。
我的 React 版本是 16.8.3
这是原始工作代码:
import React, { PureComponent } from 'react';
import videojs from 'video.js';
class VideoPlayer extends PureComponent {
componentDidMount() {
const { videoSrc } = this.props;
const { playerRef } = this.refs;
this.player = videojs(playerRef, { autoplay: true, muted: true }, () => {
this.player.src(videoSrc);
});
}
componentWillUnmount() {
if (this.player) this.player.dispose()
}
render() {
return (
<div data-vjs-player>
<video ref="playerRef" className="video-js vjs-16-9" playsInline />
</div>
);
}
}
Run Code Online (Sandbox Code Playgroud)
添加 React …
angular ×8
typescript ×4
meteor ×2
ngrx ×2
rxjs5 ×2
angularjs ×1
javascript ×1
mongodb ×1
npm ×1
plunker ×1
react-hooks ×1
reactjs ×1