Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component } from '@angular/core';
- @Component({
- selector: 'my-app',
- templateUrl: './app.component.html',
- styleUrls: [ './app.component.css' ]
- })
- export class AppComponent {
- sampleObj = [
- {'checked': false, name: 'option 1'},
- {'checked': false, name: 'option 2'},
- {'checked': false, name: 'option 3'},
- {'checked': true, name: 'option 4'}
- ];
- sampleFunc(event, i) {
- if (event.currentTarget.checked) {
- alert(i);
- this.sampleObj[i].checked = false;
- }
- }
- }
- <div *ngFor="let item of sampleObj; let i = index">
- <input type='checkbox' name='item{{i}}' [(ngModel)]="item.checked" (change)="sampleFunc($event, i)" />
- <label for='item{{i}}'><span>{{item.name}}</span></label>
- </div>
- Angular CLI: 7.1.1
- Node: 10.14.2
- OS: win32 x64
- Angular: 7.1.1
- ... animations, cdk, cli, common, compiler, compiler-cli, core
- ... forms, language-service, material, platform-browser
- ... platform-browser-dynamic, router
- Package Version
- -----------------------------------------------------------
- @angular-devkit/architect 0.11.1
- @angular-devkit/build-angular 0.12.1
- @angular-devkit/build-optimizer 0.12.1
- @angular-devkit/build-webpack 0.12.1
- @angular-devkit/core 7.1.1
- @angular-devkit/schematics 7.1.1
- @angular/pwa 0.11.2
- @angular/service-worker 7.1.2
- @ngtools/webpack 7.2.1
- @schematics/angular 7.1.1
- @schematics/update 0.11.1
- rxjs 6.3.3
- typescript 3.1.6
- webpack 4.23.1
Add Comment
Please, Sign In to add comment