首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在我的应用程序中使用ngModel作为全局?

如何在我的应用程序中使用ngModel作为全局?
EN

Stack Overflow用户
提问于 2018-06-21 14:09:06
回答 1查看 75关注 0票数 0

我想要显示从添加屏幕到视图屏幕的值基于ngModel,我尝试了,但没有成功。我是Angular 5的新手。如果我在添加屏幕中添加了值,应该会显示在View screen表中。

//this is my App.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import {RouterModule, Routes} from '@angular/router';
import {Component} from '@angular/core';
import {NgForm} from '@angular/forms';
import {FormsModule} from '@angular/forms';

import { AppComponent } from './app.component';
import { HeaderComponent } from './header/header.component';
import { BodyComponent } from './body/body.component';
import { FooterComponent } from './footer/footer.component';
import { UomComponent } from './uom/uom.component';
import { AddComponent } from './uom/add/add.component';
import { DetailsComponent } from './uom/details/details.component';
import { DeleteComponent } from './uom/delete/delete.component';

  const appRoutes: Routes = [
   {path: 'viewUom', component: UomComponent},
  {path: 'addUom', component: AddComponent},
  {path: 'detailsUom', component: DetailsComponent},
  {path: 'deleteUom', component: DeleteComponent},

  ];
@NgModule({
  declarations: [
    AppComponent,
    HeaderComponent,
    BodyComponent,
    FooterComponent,
    UomComponent,
    AddComponent,
    DetailsComponent,
    DeleteComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
     RouterModule.forRoot(appRoutes) // if required {enableTracing: true}
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {}



// This is my Add.component.ts 
import {NgForm} from '@angular/forms';
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-add',
  templateUrl: './add.component.html',
  styleUrls: ['./add.component.css']
})
export class AddComponent implements OnInit {
  itemId = '1111';
  constructor() { }

  ngOnInit() {
  }

}
/* New Buttons */
.button-band .buttons {position:absolute;top:1px;right:0;float:right;width:auto;margin-right:10px;margin-top:.1%;}
.buttons1 .main-btns {position: relative;display: inline-block;width: auto;}
.main-btns a {display: inline-block;padding: 1px 10px;border: 1px solid #3D81A9;border-radius: 5px;font-family: Arial, Helvetica, sans-serif;background: #014D82;background: linear-gradient(#0272A5, #014D82);background: -moz-linear-gradient(#0272A5, #014D82);background: -webkit-linear-gradient(#0272A5, #014D82);text-decoration: none;color: white;width: auto;max-width: 150px;height: 22px;line-height:14px;margin: 0;margin-left: 3px;text-align:center;vertical-align: middle;}
.main-btns a:focus {outline: 1px dotted #000;}
.main-btns a.but-disbl {color:#dddddd;border:1px solid #8fb0c1;background:#8ebdd7;background:linear-gradient(#8ebdd7, #87b3d0);background:-moz-linear-gradient(#8ebdd7, #87b3d0);background:-webkit-linear-gradient(#8ebdd7, #87b3d0);cursor:default;}
.main-btns a.but-disbl:hover {color:#dddddd;border:1px solid #8fb0c1;background:#8ebdd7;background:linear-gradient(#8ebdd7, #87b3d0);background:-moz-linear-gradient(#8ebdd7, #87b3d0);background:-webkit-linear-gradient(#8ebdd7, #87b3d0);}
.main-btns a span {display:inline-block;width:auto;max-width:100px;font-size:11px;white-space:nowrap;overflow:hidden;margin:2px 0;}
.main-btns a:hover {background:#02689b;color:#fff;}
/* New Buttons END*/
.buttons a {display: inline-block;padding: 1px 10px;border: 1px solid #3D81A9;border-radius: 5px;font-family: Arial, Helvetica, sans-serif;background: #014D82;background: linear-gradient(#0272A5, #014D82);background: -moz-linear-gradient(#0272A5, #014D82);background: -webkit-linear-gradient(#0272A5, #014D82);text-decoration: none;color: white;width: auto;max-width: 150px;height: 22px;line-height:14px;margin: 0;margin-left: 3px;vertical-align: middle;}
.buttons a:focus, .buttons-input a:focus {outline: 1px dotted #000;}
.but-menu, .excel-menu {position:absolute;display:none;width: 60px;height: auto;top:20px;left:5px;z-index:100;background: #edeef0;border: 1px solid #c2c2c2;border-bottom:none;}
.excel-menu { width:74px; }
.excel-menu1 { width:53px; }
.but-menu a, .excel-menu a {position:relative;display:inline-block;width:100%;text-decoration:none;height:auto;background: #edeef0;color: #006699;cursor:hand;border:none;border-bottom: 1px solid #c2c2c2;border-radius:0;font: normal 11px arial;padding:2px;margin:0;}
.but-menu a:hover, .excel-menu a:hover {background: #0178b2;display: inline-block;margin: 0;padding: 2px;cursor:hand;border:none;border-bottom: 1px solid #c2c2c2;color: #ffffff;}
.buttons a.but-disbl, .buttons-input a.but-disbl{color:#dddddd;border:1px solid #8fb0c1;background:#8ebdd7;background:linear-gradient(#8ebdd7, #87b3d0);background:-moz-linear-gradient(#8ebdd7, #87b3d0);background:-webkit-linear-gradient(#8ebdd7, #87b3d0);cursor:default;}
.buttons a.but-disbl:hover {color:#dddddd;border:1px solid #8fb0c1;background:#8ebdd7;background:linear-gradient(#8ebdd7, #87b3d0);background:-moz-linear-gradient(#8ebdd7, #87b3d0);background:-webkit-linear-gradient(#8ebdd7, #87b3d0);}
.buttons a span, .buttons-input a span{display:inline-block;width:auto;max-width:100px;font-size:11px;white-space:nowrap;overflow:hidden;margin:2px 0;}
.buttons a:hover, .buttons-input a:hover{background:#02689b;color:#fff;}
.buttons a.expand {display: inline-block;padding:0 10px;cursor:pointer;border-radius:50%;}
.buttons a.expand span {display:inline-block;width: 10px;height:13px;white-space:nowrap;overflow:hidden;line-height:auto;margin:2px 0;background: url('assets/images/accordionexpand.png') center top no-repeat;}
.buttons a.collapse {display: none;padding:0 10px;cursor:pointer;border-radius:50%;}
.buttons a.collapse span {display:inline-block;width: 10px;height:13px;white-space:nowrap;overflow:hidden;line-height:auto;margin:2px 0;background: url('assets/images/accordioncollapse.png') center top no-repeat;}
.buttons a.expand:focus, .buttons a.collapse:focus {outline:1px dotted #000;}
.button-gen a {display: inline-block;padding: 1px 5px;border: 1px solid #3D81A9;border-radius: 5px;font-family: Arial, Helvetica, sans-serif;background: #014D82;background: linear-gradient(#0272A5, #014D82);background: -moz-linear-gradient(#0272A5, #014D82);background: -webkit-linear-gradient(#0272A5, #014D82);text-decoration: none;color: white;width: auto;max-width: 150px;height: 20px;line-height:12px;margin: 0;margin-left: 3px;vertical-align: middle;}
.button-gen a:focus {outline: 1px dotted #000;}
.button-gen a.but-disbl {color:#dddddd;border:1px solid #8fb0c1;background:#8ebdd7;background:linear-gradient(#8ebdd7, #87b3d0);background:-moz-linear-gradient(#8ebdd7, #87b3d0);background:-webkit-linear-gradient(#8ebdd7, #87b3d0);cursor:default;}
.button-gen a.but-disbl:hover {color:#dddddd;border:1px solid #8fb0c1;background:#8ebdd7;background:linear-gradient(#8ebdd7, #87b3d0);background:-moz-linear-gradient(#8ebdd7, #87b3d0);background:-webkit-linear-gradient(#8ebdd7, #87b3d0);}
.button-gen a span {display:inline-block;width:auto;max-width:100px;font-size:11px;white-space:nowrap;overflow:hidden;margin:2px 0;}
.button-gen a:hover {background:#02689b;color:#fff;}
.gen-fx-btn-field {position: relative;display:inline-block;width: auto;}
.gen-fx-btn-field .gen-fx-field {position: relative;display: inline-block;width: 100%;padding-right: 37px;}
.gen-fx-btn-field .gen-fx-btn {position: absolute;display:inline-block;top: 0;right: 0px;}
.gen-fx-btn a{display: block;width:35px;border: 1px solid #3D81A9;border-radius: 5px;font-family: Arial, Helvetica, sans-serif;background: #014D82;background: linear-gradient(#0272A5, #014D82);background: -moz-linear-gradient(#0272A5, #014D82);background: -webkit-linear-gradient(#0272A5, #014D82);text-decoration: none;text-align:center;color: white;height: 20px;line-height:12px;vertical-align: middle;padding:2px 0}
.gen-fx-btn a span {display:inline-block;width:auto;font-size:11px;white-space:nowrap;overflow:hidden;}
.gen-fx-btn .gen-fx-btn-dsbld {border:1px solid #8fb0c1;background:#8ebdd7;background:linear-gradient(#8ebdd7, #87b3d0);background:-moz-linear-gradient(#8ebdd7, #87b3d0);background:-webkit-linear-gradient(#8ebdd7, #87b3d0);color:#ddd;cursor:default;}
.gen-fx-btn-dsbld span {display:inline-block;width:auto;font-size:11px;white-space:nowrap;overflow:hidden;}
.button-gen-fx a {display: inline-block;padding: 0px 5px;border: 1px solid #3D81A9;border-radius: 5px;font-family: Arial, Helvetica, sans-serif;background: #014D82;background: linear-gradient(#0272A5, #014D82);background: -moz-linear-gradient(#0272A5, #014D82);background: -webkit-linear-gradient(#0272A5, #014D82);text-decoration: none;color: white;width: auto;max-width: 150px;height: 20px;line-height:12px;margin: 0;margin-left: 3px;vertical-align: middle;}
.button-gen-fx a:focus {outline: 1px dotted #000;}
.button-gen-fx a.but-disbl {color:#dddddd;border:1px solid #8fb0c1;background:#8ebdd7;background:linear-gradient(#8ebdd7, #87b3d0);background:-moz-linear-gradient(#8ebdd7, #87b3d0);background:-webkit-linear-gradient(#8ebdd7, #87b3d0);cursor:default;}
.button-gen-fx a.but-disbl:hover {color:#dddddd;border:1px solid #8fb0c1;background:#8ebdd7;background:linear-gradient(#8ebdd7, #87b3d0);background:-moz-linear-gradient(#8ebdd7, #87b3d0);background:-webkit-linear-gradient(#8ebdd7, #87b3d0);}
.button-gen-fx a span {display:inline-block;width:auto;max-width:100px;font-size:11px;white-space:nowrap;overflow:hidden;margin:2px 0;}
.button-gen-fx a:hover {background:#02689b;color:#fff;}
<!-- this is main screen -->
<div class="button-band"><span class="header-m">&nbsp;Search Criteria</span><div class="buttons"><a routerLink="/viewUom" routerLinkActive ="active" title="View"><span>View</span></a><a routerLink="/addUom" title="Add"><span>Add</span></a><a routerLink="/detailsUom" title="Details"><span>Details</span></a><a routerLink="/deleteUom" title="Delete"><span>Delete</span></a></div></div>
 <div class="viewUomClass">
 <router-outlet></router-outlet>
 </div>
<!--This is my View Screen-->
<table style="width:100%;"> 
 <thead>
 <tr height="25">
 <th width="25%">Item ID</th>
 <th width="25%">Item Description</th>
 <th width="25%">Item classification</th>
 <th>Item Sub-Classification</th>
 </tr>
 </thead>
 <tbody>
 <tr height="25">
 <td>{{itemId}}</td>
 <td><!-- {{itemDescriptionVal}} --></td>
 <td><!-- {{classificationVal}} --></td>
 <td><!-- {{subClassificationVal}} --></td>
 </tr>
 </tbody>
 </table>
 
 <!--This is my Add Screen-->
 <form>
<table style="width:100%;">
<tr height="25">
<td align="right" width="45%"><div class="label-man"><span>* Item ID</span></div></td>
 
<td><input type="text" style="width:300px" name ="itemId" id="FstTex" [(ngModel)] = "itemId"></td>
</tr>
<tr height="25">
<td align="right"><div class="label-man"><span>Item Description</span></div></td>
<td><input type="text" style="width:300px" id="itemDescriptionVal"></td>
 
</tr>
<tr height="25">
<td align="right"><div class="label-man"><span>* Item Classification</span></div></td>
<td><input type="text" style="width:300px" id="classificationVal"></td>
 
</tr>
<tr height="25">
<td align="right"><div class="label-man"><span>* Item Sub-Classification</span></div></td>
<td><input type="text" style="width:300px" id="subClassificationVal"/></td>
 
</tr>
</table>
</form>

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50961463

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档