File

src/app/owners/owner-list/owner-list.component.ts

Implements

OnInit

Metadata

selector app-owner-list
styleUrls ./owner-list.component.css
templateUrl ./owner-list.component.html

Index

Properties
Methods

Constructor

constructor(router: Router, ownerService: OwnerService)
Parameters :
Name Type Optional
router Router No
ownerService OwnerService No

Methods

addOwner
addOwner()
Returns : void
ngOnInit
ngOnInit()
Returns : void
onSelect
onSelect(owner: Owner)
Parameters :
Name Type Optional
owner Owner No
Returns : void

Properties

errorMessage
Type : string
owners
Type : Owner[]
import {Component, OnInit} from '@angular/core';
import {OwnerService} from '../owner.service';
import {Owner} from '../owner';
import {Router} from '@angular/router';

@Component({
  selector: 'app-owner-list',
  templateUrl: './owner-list.component.html',
  styleUrls: ['./owner-list.component.css']
})
export class OwnerListComponent implements OnInit {
  errorMessage: string;
  owners: Owner[];

  constructor(private router: Router, private ownerService: OwnerService) {
  }

  ngOnInit() {
    this.ownerService.getOwners().subscribe(
      owners => this.owners = owners,
      error => this.errorMessage = error as any);
  }

  onSelect(owner: Owner) {
    this.router.navigate(['/owners', owner.id]);
  }

  addOwner() {
    this.router.navigate(['/owners/add']);
  }

}
<!--
  ~ /*
  ~  * Copyright 2016-2017 the original author or authors.
  ~  *
  ~  * Licensed under the Apache License, Version 2.0 (the "License");
  ~  * you may not use this file except in compliance with the License.
  ~  * You may obtain a copy of the License at
  ~  *
  ~  *      http://www.apache.org/licenses/LICENSE-2.0
  ~  *
  ~  * Unless required by applicable law or agreed to in writing, software
  ~  * distributed under the License is distributed on an "AS IS" BASIS,
  ~  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~  * See the License for the specific language governing permissions and
  ~  * limitations under the License.
  ~  */
  -->

<div class="container-fluid">
  <div class="container xd-container">
    <h2>Owners</h2>
    <div class="table-responsive">
      <table class="table table-striped">
        <thead>
        <tr>
          <th>Name</th>
          <th>Address</th>
          <th>City</th>
          <th>Telephone</th>
          <th>Pets</th>
        </tr>
        </thead>

        <tbody>
        <tr *ngFor="let owner of owners">
          <td class="ownerFullName"><a routerLink="/owners/{{owner.id}}" routerLinkActive="active"
                                       (click)="onSelect(owner)">{{ owner.firstName }} {{ owner.lastName }}</a></td>
          <td>{{ owner.address }}</td>
          <td>{{ owner.city }}</td>
          <td>{{ owner.telephone }}</td>
          <td>
        <tr *ngFor="let pet of owner.pets">
          {{ pet.name }}
        </tr>
        </td>
        </tr>
        </tbody>
      </table>
      <div>
        <button class="btn btn-default" (click)="addOwner()">Add Owner</button>
      </div>
    </div>
  </div>
</div>

./owner-list.component.css

/*
 *
 *  * Copyright 2016-2017 the original author or authors.
 *  *
 *  * Licensed under the Apache License, Version 2.0 (the "License");
 *  * you may not use this file except in compliance with the License.
 *  * You may obtain a copy of the License at
 *  *
 *  *      http://www.apache.org/licenses/LICENSE-2.0
 *  *
 *  * Unless required by applicable law or agreed to in writing, software
 *  * distributed under the License is distributed on an "AS IS" BASIS,
 *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  * See the License for the specific language governing permissions and
 *  * limitations under the License.
 *
 */

Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""