我一直找不到关于这个主题的任何东西,所以我想我会问。
我目前正在我的Angular 5 应用程序上编写 E2E 测试。E2E 由Protractor执行,如默认 Angular CLI 生成器项目中的配置。我需要能够在 E2E 测试中更改文本输入字段的值。
我当前的代码。
...
it('should submit report.',() => {
page.setField("100");
...
Run Code Online (Sandbox Code Playgroud)
上面引用了这个类和方法
import { browser, by, element } from 'protractor';
export class Page {
setField(text: string): Page {
let field = element(by.id('myField'));
field.sendKeys(text);
return this;
}
...
Run Code Online (Sandbox Code Playgroud)
和我的 html。
<input id="myField" decimal="16" dataLoadedEvent="{{formatData}}" [(ngModel)]="rm.dataField" class="form-control input-sm">
Run Code Online (Sandbox Code Playgroud)
这很简单。显然,我已经将它概括为消费......但希望它仍然能说明问题。
注意事项:
如果我从 html 输入字段中删除以下内容, .sendKeys() 工作
decimal="16" dataLoadedEvent="{{formatData}}" [(ngModel)]="rm.dataField"
Run Code Online (Sandbox Code Playgroud)如果我只是删除
decimal="16" dataLoadedEvent="{{formatData}}"
Run Code Online (Sandbox Code Playgroud)
sendKeys() 仍然不起作用。这意味着问题出在字段上的 [(ngModel)] 绑定上。不适用于我的自定义十进制格式指令。
所以,我的问题是,我需要做什么才能使 …
我通过了this,并了解到在声明了数据绑定的输入属性之后,Angular应该自动更新输入值。在我创建的组件中,似乎并非如此。
当我单击父级网格上的项目时,它会正确显示详细信息。之后,当我单击另一个项目时,它不会更新子组件。我放置了console.log来监视所选记录。它会根据用户选择不断变化。
您能否看一下,并帮助我了解问题所在?
listing.component.html [父母]
<div class="container-fluid">
<div class="row mt-2 mb-2">
<div class="col-8">
<app-list-item-add *ngIf="showAddnewScreen" (notifyParentOnUpdate)='onAddItem($event)'></app-list-item-add>
<app-list-item-view *ngIf="showViewScreen" [studentObject]="selectedstudent" (notifyParentOnUpdate)='onViewItem($event)'></app-list-item-view>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
list.component.ts [父母]
import { Component, OnInit, ViewChild } from '@angular/core';
import { studentsService, student } from '../services/students.service';
import { Router, ActivatedRoute } from '@angular/router';
import { GridComponent, ToolbarItems, SortEventArgs, RowSelectEventArgs, SelectionSettingsModel } from '@syncfusion/ej2-ng-grids';
import { ClickEventArgs } from '@syncfusion/ej2-ng-navigations';
import * as moment from 'moment';
import { Internationalization } from '@syncfusion/ej2-base';
@Component({
selector: 'app-lists', …
Run Code Online (Sandbox Code Playgroud) data-binding parent-child typescript angular two-way-binding
在角度2中是否有任何方法,以便我们可以像在角度1中那样实现单向数据绑定.
<!DOCTYPE html>
<html lang="en-US">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>
<div ng-app="">
<h4>please change the text box value to see the scenario</h4>
<p>Name : <input type="text" ng-model="name"
ng-init="name='change me '"></p>
<h1>Hello {{name}}</h1>
<h2>One-way binding- </h2>
{{::name}}
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我们如何以Angular 2的方式实现这一目标.我们有什么替代品.
注意:我不想仅反映HTML上的更改.我需要更新的值@component end,但我不想仅在UI上显示更改
我想在Android中使用数据绑定在数组上实现双向绑定。
这是我拥有的代码的简化版本:
<data>
<variable
name="values"
type="Integer[]" />
</data>
<EditText
...
android:text="@={Converter.toString(values[0])} />
Run Code Online (Sandbox Code Playgroud)
但是当我尝试构建此代码时,我收到如下消息:
cannot find method setTo(java.lang.Integer[], int, java.lang.Integer) in class android.databinding.ViewDataBinding
如果可能的话,如何实现与数组的双向绑定?
我有一个类型为 number 的输入字段。当用户输入多个零 (0) 并移动到下一个输入字段时,多个零应该回到单个 0。
我在 plunkr 中尝试了以下代码:https ://plnkr.co/edit/dyCp5ZMKOkZvcsw4F8og ? p = preview
<input [(ngModel)]="value" type="number" class="form-control" id="valueId"
(ngModelChange)="valuechange($event)">
valuechange(newValue) {
//newValue = newValue.toString().replace(/^0+/, '0');
newValue=parseInt(newValue.toString());
console.log(newValue);
}
Run Code Online (Sandbox Code Playgroud) 我偶然发现了 Microsoft ASP.NET 的 WingTipToy 项目,其中代码行使用 <%#: 而不是 <%#
这里真正的主要区别是什么?
我无法理解父组件和子组件之间的双向绑定。到目前为止,我读到的内容似乎建议将 prop.sync 与观看道具结合使用。例如:
家长:
<child-component :childProp.sync="parentData"></child-component>
Run Code Online (Sandbox Code Playgroud)
孩子:
<template>
<input v-model="childData" @input="$emit('update:childProp', childData);"></input>
</template>
<script>
export default {
props: ['childProp'],
data() {
childData: childProp
},
watch: {
childProp(newValue) {
this.childData = newValue;
}
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
我的问题是,当父数据或子数据更新时,这不会产生某种冗余吗?流程将是这样的(对于已更改的parentData):
我假设循环在步骤#5 处停止,因为parentData 的更新值与旧值相同,因此parentData 并没有真正改变,因此不会触发步骤#2 观察程序。
我的问题是,如果我的推理是正确的,那么对parentData的更改将传递给子级并反射回自身,从而会存在某种冗余,反之亦然。反射就是冗余。到目前为止我是对的吗?还是我对此的理解完全错误?
如果我错了,请帮助我理解我错在哪里。但如果我是对的,那么还有另一种方法可以实现双向绑定而不需要这种冗余吗?
我可以在一个函数中为两个不同的输入进行双向绑定吗?
为了绑定:
<Input placeholder='title...' onChange={this.handelChangetitle.bind(this)} />
<textarea className='textarea' onChange={this.handelChangecontent.bind(this)}>d</textarea>
Run Code Online (Sandbox Code Playgroud)
到:<p>Blog title:{this.state.title}</p>
<p>Blog content:{this.state.content}</p>
我需要两个非常相似的功能:
handelChangetitle(event){this.setState({title:event.target.value})}
handelChangecontent(event){this.setState({content:event.target.value})}
Run Code Online (Sandbox Code Playgroud)
有什么方法可以保存一些代码,只使用一个函数但同时绑定“标题”和“内容”?
我在android中有一个组合视图,其中包含几个textViews和一个EditText。我定义的属性我叫自定义视图text
和getText
,setText
方法。现在,我想为自定义视图添加一种2方向数据绑定,将其绑定到内部编辑文本,因此,如果我的数据得到更新,则编辑文本也应同时更新(现在可以使用),并且当我的编辑文本得到更新时,数据也应更新。
我的绑定类看起来像这样
@InverseBindingMethods({
@InverseBindingMethod(type = ErrorInputLayout.class, attribute = "text"),
})
public class ErrorInputBinding {
@BindingAdapter(value = "text")
public static void setListener(ErrorInputLayout errorInputLayout, final InverseBindingListener textAttrChanged) {
if (textAttrChanged != null) {
errorInputLayout.getInputET().addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
textAttrChanged.onChange();
}
});
}
}
}
Run Code Online (Sandbox Code Playgroud)
我试图用下面的代码绑定文本。userInfo …
data-binding android android-binding-adapter two-way-binding
在 html 方面我有:
<mat-select #footageSelects [(ngModel)]="selectedItems[element.id]">
<ng-container *ngFor='let opt of element.items; index as index'>
<mat-option [value]="opt">{{opt.label}}
</mat-option>
</ng-container>
</mat-select>
Run Code Online (Sandbox Code Playgroud)
在 ts 方面我有:
@ViewChildren('footageSelects') _footageSelects: QueryList<ElementRef>;
....
this._footageSelects.toArray().map(x => {
setTimeout(() => {
//sets a value in the select if not defined or no more in the options
if (!x['options'].some(y => y['value'] === x['value'])) {
x['value'] = x["options"]["first"]["value"];
}
});
});
Run Code Online (Sandbox Code Playgroud)
此代码描述了一个组件列表mat-select
,如果所选值不再位于其各自可能的选项列表中,则可以更新该列表。我的问题是,其中每一个都通过双向绑定链接到对象的条目selectedItems
,但是在分配x['value'] = ...
新值时不会在selectedItems
. 直接更改上面代码片段中的字典并不容易,因为我没有相关的密钥。除此之外还有其他方法x['value'] = ...
可以保留这里的双重绑定吗?
这是我指出的行为的示例:
two-way-binding ×10
angular ×3
data-binding ×3
javascript ×2
android ×1
angular5 ×1
angularjs ×1
arrays ×1
asp.net ×1
e2e-testing ×1
parent-child ×1
protractor ×1
reactjs ×1
typescript ×1
vb.net ×1
vue.js ×1