我刚刚开始尝试,ngxs但从我的阅读到目前为止,我还没有100%清楚我应该回调我的API来坚持和读取数据(我看到的所有例子都没有这样做,或者使用一些模拟).
例如,我创建了一个维护项目列表的状态.当我想添加一个项目时,我将'AddItem`动作发送到商店,在那里我将新项添加到状态.这一切都运行正常 - 问题是插入将项目POST到服务器的调用的适当位置在哪里?
我应该在我的动作实现中调用API,即在更新商店的项目列表之前.
或者我应该在我的Angular组件中调用API(通过服务),然后在收到响应时调度"添加项目"操作?
我对这个领域很陌生,所以这些方法的任何指导或优点/缺点都会很棒.
我在Angular 2.1中有一个模板驱动的表单,包含许多标准控件(<input>, <select>等)和一个自定义控件,它本身包含多个输入元素.
我已经在自定义控件上实现了ControlValueAccessor,并且它正确地将它的已更改/触摸/有效值传播到父窗体.
但是..在父窗体上我有一个保存按钮,保存后我想要清除脏/触摸状态(因为这会影响应用的css),如下所示:
save(myForm: NgForm) {
myForm.form.markAsPristine();
myForm.form.markAsUntouched();
}
Run Code Online (Sandbox Code Playgroud)
这适用于顶级父窗体和自定义控件本身中的所有元素,但自定义控件中的<input>字段仍标记为触摸/脏(并且接收预先保存的样式).
是否有一种方法可以在更改脏/触摸状态时通知自定义控件,以便它可以清除它的子<input>元素以匹配?似乎如果<input>元素在自定义控件中,则不会通过在父窗体上调用markAsPristine/Untouched来更新它们.
谢谢!
我正在Angular 2中构建一个表单.构建提交表单的过程很简单,但我还需要一个编辑功能.我的问题是我不明白如何从后端预先填充表单中的数据.我有一个后端服务,我从中获取数据.但我不知道这些数据将如何绑定到现有表单.
表格的代码如下: -
组件代码
import { Component, OnInit } from '@angular/core';
import { DialogRef, ModalComponent, CloseGuard } from 'angular2-modal';
import { BSModalContext } from 'angular2-modal/plugins/bootstrap';
import { ValidationService } from '../../../shared/core/error-messages/validation-service';
import { FormGroup, FormControl, Validators, FormBuilder, FormArray }
from '@angular/forms';
export class CustomModalContext extends BSModalContext {
public num1: number;
public num2: number;
}
/**
* A Sample of how simple it is to create a new window, with its own injects.
*/
@Component({
selector: 'modal-content',
templateUrl: './custom-modal.component.html'
}) …Run Code Online (Sandbox Code Playgroud) 我正在使用VS2017 Preview中用于Azure Functions项目的新工具,并将某些功能从Azure门户移植到了新项目中。
我正在绑定到Azure文档数据库-它工作正常,但是当我使用该DocumentDB属性时,我必须提供数据库名称作为第一个参数。
以我为例,现在是DEV数据库。但是当然会有其他环境-是否可以通过函数app的应用程序设置来获取数据库名称?
[FunctionName("TimerTriggeredFunction")]
public static void Run([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer, TraceWriter log,
[DocumentDB("my-db-DEV", "MyCollection")] IEnumerable<dynamic> inputDocuments)
Run Code Online (Sandbox Code Playgroud) 使用NGXS @Select装饰器时,访问状态模型中定义的属性的正确方法是什么.
例如,定义了以下状态:
export interface UserStateModel {
firstname: string;
lastname: string;
}
@State<UserStateModel>({
name: 'user',
defaults: {}
})
export class UserState {..}
Run Code Online (Sandbox Code Playgroud)
在组件中,如果我想选择这样的用户状态:
..export class MyComponent {
@Select(UserState) user$: Observable<UserState>;
ngOnInit(){
this.user$.subscribe(u => {
//do something with user state
console.log(u.firstname);
});
}
}
Run Code Online (Sandbox Code Playgroud)
我得到了打字稿错误,因为该firstname属性不存在UserState(因为它是在相关的模型类型上定义的).如果我在组件html模板中引用该属性,那么我没有任何问题.
有一个关于选择器使用的相关讨论,但我只想确认我对当前版本的期望(如果我正确地做到这一点!).
我正在使用 "@ngxs/store": "^3.0.0-rc.2",
嗨,我有如下一组按钮,
let Btns: Array<any> = [{
type: "submit",
BtnType: "prev",
label: "Previous",
class: "btn-outline",
icon: "kd-back",
disabled: false
},
{
type: "submit",
BtnType: "next",
label: "Next",
icon: "kd-play",
class: "btn-text",
disabled: false
}];
Run Code Online (Sandbox Code Playgroud)
我也有两个变量:
private nextBtn_disabled: boolean = false;
private prevBtn_disabled: boolean = true;
Run Code Online (Sandbox Code Playgroud)
我正在为按钮实现禁用功能。行为是这样的:
以下是我的HTML:
<div class="form-group text-center">
<button *ngFor="let btn of Btns" [type]="(btn.type=='submit')?'submit':'button'" class="btn btn-icon" [ngClass]="btn.class" (click)="_btnClick(btn, _finalConfig)" [disabled]="nextBtn_disabled">
<i *ngIf="btn.BtnType!='next'" [class]="btn.icon"></i>
<span>{{btn.label}}</span>
<i *ngIf="btn.BtnType=='next'" [class]="btn.icon"></i>
</button>
</div>
Run Code Online (Sandbox Code Playgroud)
我该如何实现?我试过||条件和&&之间的条件nextBtn_disabled和 prevBtn_disabled …