我正在努力了解ngrx /效果.我已经构建了一个简单的函数,每次单击都会将数字增加1.但点击时它会进入无限循环,不确定是什么时候发生的.我确定我犯了一些愚蠢的错误.
monitor.effects.ts
@Injectable()
export class MonitorEffects {
@Effect()
compute$: Observable<Action> = this.actions$
.ofType(monitor.ActionTypes.INCREMENT)
.map((action: monitor.IncrementAction) => action.payload)
.switchMap(payload => {
return this.http.get('https://jsonplaceholder.typicode.com/users')
.map(data => new monitor.IncrementAction(payload+1))
.catch(err => of(new monitor.InitialAction(0)))
});
constructor(private actions$: Actions, private http:Http ) {};
}
Run Code Online (Sandbox Code Playgroud)
monitor.component.ts
ngOnInit() {
this.storeSubsciber = this
.store
.select('monitor')
.subscribe((data: IMonitor.State) => {
this.value = data.value;
this.errorMsg = data.error;
this.currentState = data.currentState;
});
}
increment(value: number) {
this.store.dispatch(new monitorActions.IncrementAction(value));
}
Run Code Online (Sandbox Code Playgroud)
monitor.reducer.ts
export const monitorReducer: ActionReducer<IMonitor.State> = (state = initialState, action: Actions) …Run Code Online (Sandbox Code Playgroud) 当我的模型值是,true然后我希望加载时选择单选按钮,但它发生在另一边.所有false型号都被选中.如何解决这个问题.
http://plnkr.co/edit/DIYm4vBM3srdS61K6EPA?p=preview
angular.module('radioExample', [])
.controller('ExampleController', ['$scope',
function($scope) {
$scope.kind = [{
name: 'task',
selected: false
}, {
name: 'bug',
selected: false
}, {
name: 'other',
selected: true
}, {
name: 'rfe',
selected: false
}]
$scope.$watch('kind', function() {
console.log('changed', JSON.stringify($scope.kind, null, 2))
}, true)
}
]);
Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个树组件,其中od-tree-node组件递归嵌套以构建子节点。我在处理事件时遇到问题。对于叶子节点上的点击事件,鼠标事件总是触发,就好像事件发生在最顶部的组件上一样。我不知道如何处理这个。
预期行为:当用户单击叶/父/根节点时,父组件(例如:)app.component.ts需要知道单击了哪个节点。
当前行为:无论点击哪个节点,都选择根节点(发射到父组件)
plunker : https://plnkr.co/edit/JZTlA5?p=preview
这是模板:
节点.component.html
<!-- parent node -->
<label [attr.for]="resource.resourceType" [class]="cssClasses" *ngIf="resource.hasChildren()" [hidden]="matchedChildrenCount(search, resource) === 0">
<a (click)="toggleNode($event)"> <i [class]="getNodeStateIcon()"></i></a>
<input type="checkbox" *ngIf="showCheckboxes" [checked]="selected">
<a [title]="resource.resourceName" (click)="selectNode($event);">
<i [class]="resource.getIcon()"></i> {{resource.resourceName}} | {{ matchedChildrenCount(search, resource) | lpad : 2 : '0'}}
</a>
</label>
<!-- leaf node -->
<label [attr.for]="resource.resourceType" [class]="cssClasses" *ngIf="!resource.hasChildren()" [hidden]="!isMatched(search, resource)">
<input type="checkbox" *ngIf="showCheckboxes" [checked]="selected">
<a [title]="resource.resourceName" (click)="selectNode($event);">
<i class="icon-status-indicator"></i> {{resource.resourceName}}
<div class="group" *ngIf="resource?.group !== 'Default'">{{resource.group}}</div>
</a>
</label>
<!-- recrusive child …Run Code Online (Sandbox Code Playgroud) 这是一个简单的Perl脚本,它接受2个参数 - 一个字符串(一个URL)和一个整数值.
我所要做的就是在给定的时间段(以秒为单位)内对传递的URL运行curl请求.
当URL很简单时,一切都很好,http://admin:admin@localhost:5074/?q=james但是当&URL中存在问题时会出现问题.
问题是system(),即使退出循环,curl请求仍会继续运行.
这是怎么回事?
use strict;
use warnings;
use URI::Escape;
my $url = uri_escape($ARGV[0]);
print "URL=".$url."\n";
my $duration = $ARGV[1];
print $duration;
my $start = time();
my $end = $start + $duration;
my $request = 0;
while(time() <= $end ){
system("curl --user admin:admin --digest ".uri_unescape($url));
$request++;
}
print "------------------------ END ----------------------------------\n";
print "URL = ".uri_unescape($url)." \n";
print "Total requests made = ".$request."\n";
print "Reqs/sec = ".($request/$duration)."/sec \n";
#print $start."\n";
#print $end."\n"; …Run Code Online (Sandbox Code Playgroud) 我正在尝试预选列表中由ng-options指令生成的项目.有人可以告诉我发生在plunker中的事情吗?
http://plnkr.co/edit/GTnR76HEnB5NxQRe484m?p=preview
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js"></script>
<script>
function MyCntrl($scope) {
$scope.prop = {
"type": "select",
"name": "Service",
"values": [{
'name': "Service 1"
}, {
'name': "Service 2"
}, {
'name': "Service 3"
}, {
'name': "Service 4"
}]
};
$scope.selected1 = $scope.prop.values[1]
$scope.selected2 = {
"name": "Service 2"
}
}
</script>
</head>
<body>
<div ng-controller="MyCntrl">
Works <br>
<select ng-model="selected1" ng-options="v.name for v in prop.values">
</select> {{selected1}} <br>
Does not work. Why? <br>
<select ng-model="selected2" ng-options="v.name for v in prop.values">
</select>
{{selected2}} …Run Code Online (Sandbox Code Playgroud) angular ×2
angularjs ×2
javascript ×1
ng-options ×1
ngrx ×1
perl ×1
radio-button ×1
recursion ×1
redux ×1
side-effects ×1