- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我在 Angular 2 中的网站进展得越多,Elvis Operator
似乎就越多。是使这一切成为可能的神奇力量。我采取的每一步都涉及弄清楚如何将它正确地应用于对数据完成的所有事情的每个实例。我觉得需要一个 ?
是否“正常”关于你在现实生活中使用实际数据所做的几乎所有事情,Angular 文档都会提到它。
举个例子,我最近才学会如何设置FormGroups
对于 react 形式。按照 Angular.io 上的步骤,我的表单组看起来像这样。
createForm() {
this.quesForm = this.fbuild.group({
question: this.featureQuestion.question,
id : this.featureQuestion.id,
name : this.featureQuestion.name,
answers : this.fbuild.array([])
});
this.setAnswers(this.featureQuestion.answers);
}
get answers(): FormArray {
return this.quesForm.get('answers') as FormArray;
};
mock-data
一起工作我在
const
中创建它工作得很好。然而,当我想用“真实数据”“真实世界使用”它时,我不得不再花 3 到 4 天的时间发现我需要这样做。
createForm() {
this.quesForm = this.fbuild.group({
question: this.featureQuestion ? this.featureQuestion.question: '',
id : this.featureQuestion ? this.featureQuestion.id: '',
name : this.featureQuestion ? this.featureQuestion.name: '',
answers : this.fbuild.array([])
});
this.setAnswers(this.featureQuestion ? this.featureQuestion.answers: []);
}
@Input
都没有关系和
@Output
,或在函数中做某事;
Elvis Operator
是桥上的巨魔带着一个疯狂的谜语需要一周的时间才能弄清楚只是为了做我已经认为我学到的东西。起初我认为这只是他们必须解决的一个小怪癖,但现在这对我个人来说太大了,不能成为他们最终的一个错误,否则我认为会有更广泛的信息,因为这意味着没有人能够在现实生活中使用 Angular,而无需每一步都应用它。这意味着它必须是我正在做的事情。
export class HomeService {
BusImage : FirebaseObjectObservable<any>;
constructor(private af: AngularFire) {}
getBusImage() {
this.BusImage = this.af.database.object('/page_area_business_image')
as FirebaseObjectObservable<any>
return this.BusImage;
}
}
export class ExpBusinessComponent implements OnInit {
private busImageO : FirebaseObjectObservable<any>;
private busImageQues01O : FirebaseObjectObservable<any>;
private busImageQues02O : FirebaseObjectObservable<any>;
constructor(private _homeService: HomeService) {}
ngOnInit() {
this._homeService.getBusImage().subscribe(BusImage => {
this.busImageO = BusImage.expand;
this.busImageQues01O = BusImage.questions.question01;
this.busImageQues02O = BusImage.questions.question02;
});
}
}
<h1>{{busExpInformation?.title}}</h1>
<p>{{busExpInformation?.intro}}</p>
<business-image
[busImageI] = "busImageO"
[busImageQues01I] = "busImageQues01O"
[busImageQues02I] = "busImageQues02O">
</business-image>
export class BusinessImageComponent implements OnChanges, OnInit {
@Input('busImageI') busImage : FirebaseObjectObservable<any>;
@Input('busImageQues01I') question01 : FirebaseObjectObservable<any>;
@Input('busImageQues02I') question02 : FirebaseObjectObservable<any>;
public selectedI(selected){ this.selectedAnswer = selected };
selectedAnswer: any;
expbTrigger : boolean = false;
expb2Trigger : boolean = false;
}
<multiple-choice-radio *ngIf="expbTrigger"
[question] = "question01"
(selectedO) = "selectedI($event)"
></multiple-choice-radio>
export class MultipleChoiceRadioComponent implements OnInit, OnChanges {
@Input('question') featureQuestion: QuestionModel;
@Output() selectedO: EventEmitter<any> = new EventEmitter();
selected = {value1: '', value2: ''};
quesForm: FormGroup;
public sendAnswer = (): void => {
this.selectedO.emit(this.selected);
}
constructor(private fbuild : FormBuilder) {}
ngOnChanges() {
this.createForm();
}
createForm() {
this.quesForm = this.fbuild.group({
question: this.featureQuestion ? this.featureQuestion.question: '',
id : this.featureQuestion ? this.featureQuestion.id: '',
name : this.featureQuestion ? this.featureQuestion.name: '',
answers : this.fbuild.array([])
});
this.setAnswers(this.featureQuestion ? this.featureQuestion.answers: []);
}
get answers(): FormArray {
return this.quesForm.get('answers') as FormArray;
};
setAnswers(answers : Answers[]){
const answersFGs = answers.map(answers => this.fbuild.group(answers));
const answersFormArray = this.fbuild.array(answersFGs);
this.quesForm.setControl('answers', answersFormArray);
}
getSelected(ans) {
this.selected = { value1: ans.id, value2: ans.answer };
}
}
<form [formGroup]="quesForm" novalidate>
<fieldset [attr.id]="quesForm.value.id">
<label>
{{quesForm.value.question}}
</label>
<div>
<div *ngFor="let ans of quesForm.value.answers">
<div>
<input type="radio"
[attr.name] = "quesForm.value.name"
[attr.id] = "ans.id"
[attr.value] = "ans.answer"
(click) = "getSelected(ans)"
(click) = "sendAnswer()"
hidden
/>
<label [attr.for]="ans.id">
{{ans.answer}}
</label>
</div>
</div>
</div>
</fieldset>
</form>
@Output
将选定的值发送给父级只会在我用
| json
做的一些测试绑定(bind)中给出结果整个对象上的管道,但记录为未定义所以如果你觉得我的做法有问题,我已经知道它不能正常工作。
defined
是因为
GrandChild Component
将在网站的其他地方用于其他问题。有时我只会使用
id
为了触发逻辑,有时我会将答案提取到将保存到数据库的用户数据实例中。所以对我来说,仅仅将整个模型发送回链只是为了提取几个值是没有意义的,而且如果值本身可以是消除定位嵌套值的头痛的数据,考虑到我怎么不能在没有
Elvis Operator
的情况下提取我的数据在某处正确应用。
undefined
在尝试学习如何使其工作时,这非常困难,因为我不知道我是否在使其工作方面做错了什么,或者我是否在应用
Elvis Operator
方面做错了什么。到它。由于反对票和关闭它们的请求,我在这里删除了很多问题,因为从你们这些 Angular 大师的 Angular 来看,这是一个可怕的问题,或者是可怕的提问方式。所以希望有人可以帮助阐明我需要对我的数据做什么,以便能够按照 Angular.io 建议的方式做事,而无需所有额外的意外修复和解决方法,因为我正在调用一个实际的数据库而不是模拟- 本地定义的数据。
最佳答案
您正在使用响应式(Reactive)形式,这意味着无论如何您最终都会有大量 [大部分是无用的] 代码。
除非您对响应式表单有特定需求,否则只需使用模板驱动的表单。
关于angular - 如何避免需要使用 Elvis Operator?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42333943/
我正在尝试用 C 语言编写一个使用 gstreamer 的 GTK+ 应用程序。 GTK+ 需要 gtk_main() 来执行。 gstreamer 需要 g_main_loop_run() 来执行。
我已经使用 apt-get 安装了 opencv。我得到了以下版本的opencv2,它工作正常: rover@rover_pi:/usr/lib/arm-linux-gnueabihf $ pytho
我有一个看起来像这样的 View 层次结构(基于其他答案和 Apple 的使用 UIScrollView 的高级 AutoLayout 指南): ScrollView 所需的2 个步骤是: 为 Scr
我尝试安装 udev。 udev 在 ./configure 期间给我一个错误 --exists: command not found configure: error: pkg-config and
我正在使用 SQLite 3。我有一个表,forums,有 150 行,还有一个表,posts,有大约 440 万行。每个帖子都属于一个论坛。 我想从每个论坛中选择最新帖子的时间戳。如果我使用 SEL
使用 go 和以下包: github.com/julienschmidt/httprouter github.com/shwoodard/jsonapi gopkg.in/mgo.v2/bson
The database仅包含 2 个表: 钱包(100 万行) 事务(1500 万行) CockroachDB 19.2.6 在 3 台 Ubuntu 机器上运行 每个 2vCPU 每个 8GB R
我很难理解为什么在下面的代码中直接调用 std::swap() 会导致编译错误,而使用 std::iter_swap 编译却没有任何错误. 来自 iter_swap() versus swap() -
我有一个非常简单的 SELECT *用 WHERE NOT EXISTS 查询条款。 SELECT * FROM "BMAN_TP3"."TT_SPLDR_55E63A28_59358" SELECT
我试图按部分组织我的 .css 文件,我需要从任何文件访问文件组中的任何类。在 Less 中,我可以毫无问题地创建一个包含所有文件导入的主文件,并且每个文件都导入主文件,但在 Sass 中,我收到一个
Microsoft.AspNet.SignalR.Redis 和 StackExchange.Redis.Extensions.Core 在同一个项目中使用。前者需要StackExchange.Red
这个问题在这里已经有了答案: Updating from Rails 4.0 to 4.1 gives sass-rails railties version conflicts (4 个答案) 关
我们有一些使用 Azure DevOps 发布管道部署到的现场服务器。我们已经使用这些发布管道几个月了,没有出现任何问题。今天,我们在下载该项目的工件时开始出现身份验证错误。 部署组中的节点显示在线,
Tip: instead of creating indexes here, run queries in your code – if you're missing any indexes, you
你能解释一下 Elm 下一个声明中的意思吗? (=>) = (,) 我在 Elm architecture tutorial 的例子中找到了它 最佳答案 这是中缀符号。实际上,这定义了一个函数 (=>
我需要一个 .NET 程序集查看器,它可以显示低级详细信息,例如元数据表内容等。 最佳答案 ildasm 是 IL 反汇编程序,具有低级托管元数据 token 信息。安装 Visual Studio
我有两个列表要在 Excel 中进行比较。这是一个很长的列表,我需要一个 excel 函数或 vba 代码来执行此操作。我已经没有想法了,因此转向你: **Old List** A
Closed. This question does not meet Stack Overflow guidelines。它当前不接受答案。 想要改善这个问题吗?更新问题,以便将其作为on-topi
我正在学习 xml 和 xml 处理。我无法很好地理解命名空间的存在。 我了解到命名空间帮助我们在 xml 中分离相同命名的元素。我们不能通过具有相同名称的属性来区分元素吗?为什么命名空间很重要或需要
我搜索了 Azure 文档、各种社区论坛和 google,但没有找到关于需要在公司防火墙上打开哪些端口以允许 Azure 所有组件(blob、sql、compute、bus、publish)的简洁声明
我是一名优秀的程序员,十分优秀!