Guest User

Untitled

a guest
Jan 18th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. import { Component } from '@angular/core';
  2.  
  3. @Component({
  4. selector: 'my-app',
  5. templateUrl: './app.component.html',
  6. styleUrls: [ './app.component.css' ]
  7. })
  8. export class AppComponent {
  9. sampleObj = [
  10. {'checked': false, name: 'option 1'},
  11. {'checked': false, name: 'option 2'},
  12. {'checked': false, name: 'option 3'},
  13. {'checked': true, name: 'option 4'}
  14. ];
  15.  
  16. sampleFunc(event, i) {
  17. if (event.currentTarget.checked) {
  18. alert(i);
  19. this.sampleObj[i].checked = false;
  20. }
  21. }
  22. }
  23.  
  24. <div *ngFor="let item of sampleObj; let i = index">
  25. <input type='checkbox' name='item{{i}}' [(ngModel)]="item.checked" (change)="sampleFunc($event, i)" />
  26. <label for='item{{i}}'><span>{{item.name}}</span></label>
  27.  
  28. </div>
  29.  
  30. Angular CLI: 7.1.1
  31. Node: 10.14.2
  32. OS: win32 x64
  33. Angular: 7.1.1
  34. ... animations, cdk, cli, common, compiler, compiler-cli, core
  35. ... forms, language-service, material, platform-browser
  36. ... platform-browser-dynamic, router
  37.  
  38. Package Version
  39. -----------------------------------------------------------
  40. @angular-devkit/architect 0.11.1
  41. @angular-devkit/build-angular 0.12.1
  42. @angular-devkit/build-optimizer 0.12.1
  43. @angular-devkit/build-webpack 0.12.1
  44. @angular-devkit/core 7.1.1
  45. @angular-devkit/schematics 7.1.1
  46. @angular/pwa 0.11.2
  47. @angular/service-worker 7.1.2
  48. @ngtools/webpack 7.2.1
  49. @schematics/angular 7.1.1
  50. @schematics/update 0.11.1
  51. rxjs 6.3.3
  52. typescript 3.1.6
  53. webpack 4.23.1
Add Comment
Please, Sign In to add comment