张静樺 發表於 2019-5-20 16:04:00

angular 双向数据绑定

<p>第一步 引入FromsModule</p>
<div class="cnblogs_code">
<pre>import { BrowserModule } from '@angular/platform-browser'<span style="color: rgba(0, 0, 0, 1)">;
import { NgModule } from </span>'@angular/core'<span style="color: rgba(0, 0, 0, 1)">;
import { FormsModule } from </span>'@angular/forms'<span style="color: rgba(0, 0, 0, 1)">;
import { AppRoutingModule } from </span>'./app-routing.module'<span style="color: rgba(0, 0, 0, 1)">;
import { AppComponent } from </span>'./app.component'<span style="color: rgba(0, 0, 0, 1)">;

@NgModule({
declarations: [
    AppComponent
],
imports: [
    BrowserModule,
    FormsModule,
    AppRoutingModule
],
providers: [],
bootstrap:
})
export class AppModule { }</span></pre>
</div>
<div class="cnblogs_code">
<pre>&lt;div style="text-align:center"&gt;
&lt;h1&gt;<span style="color: rgba(0, 0, 0, 1)">
    Welcome to {{ title }}</span>!
&lt;/h1&gt;

&lt;input type="text" [(ngModel)]="inputValue"/&gt;
&lt;h1&gt;<span style="color: rgba(0, 0, 0, 1)">
    {{ inputValue }}
</span>&lt;/h1&gt;


&lt;/div&gt;</pre>
</div>
<p>&nbsp;效果图:</p>
<p><img src="https://img2018.cnblogs.com/blog/1100100/201905/1100100-20190520160405708-401799335.png" alt=""></p>

</div>
<div id="MySignature" role="contentinfo">
    最后,关注【码上加油站】微信公众号后,有疑惑有问题想加油的小伙伴可以码上加入社群,让我们一起码上加油吧!!!<br><br>
来源:https://www.cnblogs.com/loaderman/p/10894669.html
頁: [1]
查看完整版本: angular 双向数据绑定