首页 \ 问答 \ Typescript:从输入更新值(Typescript : update value from input)

Typescript:从输入更新值(Typescript : update value from input)

我有一个由* ngFor制作的餐馆列表。 我可以点击一个我想要改变的标签文本,使其成为输入字段。

我想要做的是获取输入字段的文本值,并在单击按钮时使用它更新标签值。

你会更好地理解代码:

<div class="row" *ngFor="let restaurant of event.restaurants; let index = index">
            <div class="col-xs-5" (click)="update=true" off-click="update=false">
                <input *ngIf="update" type="text" name="champ" value="{{restaurant.name}}" placeholder="{{restaurant.name}}"/>
                <a *ngIf="!update">{{restaurant.name}}</a>
            </div>
            <div class="col-xs-5">
                {{restaurant.category.description}}
            </div>
            <div class="col-xs-2">
                <button class="btn btn-default" *ngIf="!update" (click)="DelRestaurant(index)">{{'EVENT_RESTAURANT_REMOVE' | translate}}</button>
                <button class="btn btn-default" *ngIf="update" (click)="UpdateRestaurant(index)">Modifier</button>
            </div>
</div>

使用UpdateRestaurant(index) ,我想获取输入值并更改{{restaurant.name}}

如果你能帮助我,这将是真棒:)


I have a list of restaurants made by *ngFor. I can click on the one I wanna change which make it an input field with the label text in it.

What I want to do do is to get the text value of the input field and update the label value with it when I click a button.

You'll understand better with the code :

<div class="row" *ngFor="let restaurant of event.restaurants; let index = index">
            <div class="col-xs-5" (click)="update=true" off-click="update=false">
                <input *ngIf="update" type="text" name="champ" value="{{restaurant.name}}" placeholder="{{restaurant.name}}"/>
                <a *ngIf="!update">{{restaurant.name}}</a>
            </div>
            <div class="col-xs-5">
                {{restaurant.category.description}}
            </div>
            <div class="col-xs-2">
                <button class="btn btn-default" *ngIf="!update" (click)="DelRestaurant(index)">{{'EVENT_RESTAURANT_REMOVE' | translate}}</button>
                <button class="btn btn-default" *ngIf="update" (click)="UpdateRestaurant(index)">Modifier</button>
            </div>
</div>

With UpdateRestaurant(index), I want to get the input value and change {{restaurant.name}}

If you could help me that would be awesome :)


原文:https://stackoverflow.com/questions/39494083
更新时间:2024-05-02 13:05

最满意答案

在C#/ .Net对象中可以被分类为值或引用类型[1]。 值类型是从System.ValueType派生的任何类型,并且在C#中用struct类型声明定义。 这些通过复制/值传递。

引用类型是不能从System.ValueType派生的类型,并且在C#中用class关键字定义。 引用类型实例的标识符被称为引用(类似于指针)。 这些也默认通过值传递,但只有引用传递不是整个对象。

你的问题还提到string实例是通过复制传递的。 .Net中的String是引用类型(直接从System.Object派生),因此不会通过完整副本传递。

[1]指针在这里可能值得他们自己的班级,但我忽略了他们的讨论。


In C# / .Net objects can either be classified as value or reference types [1]. Value types are any type which derive from System.ValueType and are defined in C# with the struct type declaration. These are passed by copy / value.

Reference types are types which do not derive from System.ValueType and are defined in C# with the class keyword. Identifiers to instances of reference types are known as references (similar to pointers). These are also passed by value by default but only the reference is passed not the whole object.

Your question also mentioned that string instances are passed by copy. String in .Net is a reference type (derives directly from System.Object) and hence is not passed by full copy.

[1] Pointers may merit their own class here but I'm ignoring them for this discussion.

相关问答

更多
  • 有两个主要考虑因素。 一个是复制传递对象的开销,第二个是编译器在对象是本地对象时可以做出的假设。 例如,在第一种形式中,在f的主体中,不能假定a和b不引用同一个对象; 所以在写入b之后必须重新读取b ,以防万一。 在第二种形式中, a不能通过写入b来更改,因为它是函数的本地函数,所以这些重新读取是不必要的。 void f(const Obj& a, Obj& b) { // a and b could reference the same object } void f(Obj a, Obj& b ...
  • 首先,目前尚不清楚为什么要使用指针。 理想情况下,您只想直接保存对象。 然后,您不需要特殊的复制约定: TH2F RunToy(TH2F const &in); //TH2F h_migration is created and filled previously in the program for (int ntoy=0; ntoy < NTOY; ntoy++ ) { TH2F h_smearedMigration = RunToy(h_migration); 如果TH2F复制TH2F很昂 ...
  • 不要在C ++上下文中考虑pass-by-reference,因为它不一样。 var member = page_item.access_groups.member // Sets member to this value member = '1001'; // Now sets it to another value 如果在字符串上有一个更改它们的方法,那么: member.removeLastLetter(); 会改变page_item.access_groups.member 。 但是,使用you ...
  • 数据成员mStr的类型为std::string (它是一个对象,而不是引用)。 因此,在构造函数的初始化列表(通过: mStr(str) )中初始化它时,将复制通过引用传递的参数。 在您的示例中,只有初始化才会生成副本:如果删除了初始化,则不会生成副本。 The data member mStr is of type std::string (it's an object, not a reference). Therefore, when you initialize it in the construc ...
  • 当参数按值传递时,它是可以修改的,并且可以省略复制它。 例如,实现赋值运算符的规范方式如下所示: T& T::operator= (T value) { value.swap(*this); return *this; } 乍一看,它可能看起来效率低下,因为T正在被复制。 但是,无论如何它都会被复制,即如果需要复制,将会创建一种方法: T& T::operator= (T const& value) { T(value).swap(*this); // has to do a co ...
  • 在C#/ .Net对象中可以被分类为值或引用类型[1]。 值类型是从System.ValueType派生的任何类型,并且在C#中用struct类型声明定义。 这些通过复制/值传递。 引用类型是不能从System.ValueType派生的类型,并且在C#中用class关键字定义。 引用类型实例的标识符被称为引用(类似于指针)。 这些也默认通过值传递,但只有引用传递不是整个对象。 你的问题还提到string实例是通过复制传递的。 .Net中的String是引用类型(直接从System.Object派生),因此不 ...
  • 不,Java不能这样做。 Java只能通过价值传递。 它也通过值传递引用。 No, Java cannot do this. Java only passes by value. It passes references by value too.
  • 您可以使用: public void initValues(ObservableList srcList, E toEdit, UnaryOperator copy) { indexToSet = srcList.indexOf(toEdit); editing = copy.apply(toEdit); this.srcList = srcList; } 你可以用它来调用它: initValues(srcList, toEdit, YourClass::new); ...
  • 在我们使用pass by reference的C ++中,我们引用了从参数传递给函数参数的地址,该函数的参数本质上是一个指针对吗? 不可以。引用是现有变量的别名(即替代名称)。 但是在汇编级别,您的实现可能会将引用变量的地址放在地址寄存器(或类似的东西)中以供被调用函数使用(如果这就是您的意思)。 但为简化起见,您可以将其视为自动取消引用的指针(这是我第一次启动时所做的)。 但是当你进入语言时,引用实际上与指针有根本的不同。 因此虽然它们本质上是同一个东西,别名和所有,但指针也不需要内存空间吗? C ++级 ...
  • Kids *one; 似乎是未初始化的。 将值复制到它时。 这个值也是单元化的,因为它是私有的,我没有看到任何init代码。 你必须添加类似的东西 kids(new Kids()) 在Person构造函数中,不是复制一个。 PS。 不要忘记operator =和析构函数。 Kids *one; Seems to be uninitialized. When you copy a value to it. this value is also unitialized, since it is priva ...

相关文章

更多

最新问答

更多
  • sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)
  • 如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)
  • AESGCM解密失败的MAC(AESGCM decryption failing with MAC)
  • Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)
  • 湖北京山哪里有修平板计算机的
  • SimplePie问题(SimplePie Problem)
  • 在不同的任务中,我们可以同时使用多少“上下文”?(How many 'context' we can use at a time simultaneously in different tasks?)
  • HTML / Javascript:从子目录启用文件夹访问(HTML/Javascript: Enabling folder access from a subdirectory)
  • 为什么我会收到链接错误?(Why do I get a linker error?)
  • 如何正确定义析构函数(How to properly define destructor)
  • 垂直切换菜单打开第3级父级。(Vertical toggle menu 3rd level parent stay opened. jQuery)
  • 类型不匹配 - JavaScript(Type mismatch - JavaScript)
  • 为什么当我将模型传递给我的.Net MVC 4控制器操作时,它坚持在部分更新中使用它?(Why is it that when I pass a Model to my .Net MVC 4 Controller Action it insists on using it in the Partial Update?)
  • 在使用熊猫和statsmodels时拉取变量名称(Pulling variable names when using pandas and statsmodels)
  • 如何开启mysql计划事件
  • 检查数组的总和是否大于最大数,反之亦然javascript(checking if sum of array is greater than max number and vice versa javascript)
  • 使用OpenGL ES绘制轮廓(Drawing Outline with OpenGL ES)
  • java日历格式(java Calendar format)
  • Python PANDAS:将pandas / numpy转换为dask数据框/数组(Python PANDAS: Converting from pandas/numpy to dask dataframe/array)
  • 如何搜索附加在elasticsearch索引中的文档的内容(How to search a content of a document attached in elasticsearch index)
  • LinQ to Entities:做相反的查询(LinQ to Entities: Doing the opposite query)
  • 从ExtJs 4.1商店中删除记录时会触发哪些事件(Which events get fired when a record is removed from ExtJs 4.1 store)
  • 运行javascript后如何截取网页截图[关闭](How to take screenshot of a webpage after running javascript [closed])
  • 如何使用GlassFish打印完整的堆栈跟踪?(How can I print the full stack trace with GlassFish?)
  • 如何获取某个exe应用程序的出站HTTP请求?(how to get the outbound HTTP request of a certain exe application?)
  • 嗨,Android重叠背景片段和膨胀异常(Hi, Android overlapping background fragment and inflate exception)
  • Assimp详细说明typedef(Assimp elaborated type refers to typedef)
  • 初始化继承类中不同对象的列表(initialize list of different objects in inherited class)
  • 使用jquery ajax在gridview行中保存星级评分(Save star rating in a gridview row using jquery ajax)
  • Geoxml3 groundOverlay zIndex(Geoxml3 groundOverlay zIndex)