Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Commit 04b6cf9

Browse files
committed
Add angular material
1 parent 3ae6002 commit 04b6cf9

17 files changed

+155
-38
lines changed

WORKSPACE

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ http_archive(
2323
# The @angular repo contains rule for building Angular applications
2424
http_archive(
2525
name = "angular",
26-
url = "https://github.com/angular/angular/archive/7.0.1.zip",
27-
strip_prefix = "angular-7.0.1",
26+
url = "https://github.com/angular/angular/archive/7.0.2.zip",
27+
strip_prefix = "angular-7.0.2",
2828
)
2929

3030
# The @rxjs repo contains targets for building rxjs with bazel
@@ -35,6 +35,15 @@ http_archive(
3535
sha256 = "72b0b4e517f43358f554c125e40e39f67688cd2738a8998b4a266981ed32f403",
3636
)
3737

38+
# Angular material
39+
# TODO(gmagolan): update to https://github.com/angular/material2 when
40+
# https://github.com/angular/material2/pull/13836 lands
41+
http_archive(
42+
name = "angular_material",
43+
url = "https://github.com/gregmagolan/material2/archive/5373c62143a7b1a38fd6b992ed49e1c25513ff25.zip",
44+
strip_prefix = "material2-5373c62143a7b1a38fd6b992ed49e1c25513ff25",
45+
)
46+
3847
# Rules for compiling sass
3948
http_archive(
4049
name = "io_bazel_rules_sass",
@@ -97,3 +106,7 @@ sass_repositories()
97106
load("@angular//:index.bzl", "ng_setup_workspace")
98107

99108
ng_setup_workspace()
109+
110+
load("@angular_material//:index.bzl", "angular_material_setup_workspace")
111+
112+
angular_material_setup_workspace()

package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111
"zone.js": "0.8.26"
1212
},
1313
"devDependencies": {
14-
"@angular/bazel": "7.0.1",
15-
"@angular/compiler": "7.0.1",
16-
"@angular/compiler-cli": "7.0.1",
17-
"@angular/core": "7.0.1",
14+
"@angular/animations": "7.0.2",
15+
"@angular/bazel": "7.0.2",
16+
"@angular/cdk": "7.0.2",
17+
"@angular/compiler": "7.0.2",
18+
"@angular/compiler-cli": "7.0.2",
19+
"@angular/common": "7.0.2",
20+
"@angular/core": "7.0.2",
21+
"@angular/material": "7.0.2",
1822
"@bazel/benchmark-runner": "0.1.0",
1923
"@bazel/ibazel": "0.5.0",
2024
"@bazel/karma": "0.20.3",

src/BUILD.bazel

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ ng_module(
1818
tsconfig = ":tsconfig.json",
1919
deps = [
2020
"//src/hello-world",
21+
"//src/material",
2122
"//src/todos",
2223
"@angular//packages/core",
2324
"@angular//packages/router",
@@ -35,19 +36,22 @@ ts_devserver(
3536
additional_root_paths = [
3637
"npm/node_modules/zone.js/dist",
3738
"npm/node_modules/tslib",
39+
"npm/node_modules/@angular/material/prebuilt-themes",
3840
"npm/node_modules/@ngrx/store/bundles",
3941
],
4042
# Start from the development version of the main
4143
entry_module = "angular_bazel_example/src/main.dev",
4244
scripts = [
4345
":require.config.js",
46+
":module-id.js",
4447
],
4548
# This is the URL we'll point our <script> tag at
4649
serving_path = "/bundle.min.js",
4750
# Serve these files in addition to the JavaScript bundle
4851
static_files = [
4952
"@npm//node_modules/zone.js:dist/zone.min.js",
5053
"@npm//node_modules/tslib:tslib.js",
54+
"@npm//node_modules/@angular/material:prebuilt-themes/deeppurple-amber.css",
5155
"@npm//node_modules/@ngrx/store:bundles/store.umd.min.js",
5256
"index.html",
5357
],
@@ -93,13 +97,22 @@ genrule(
9397
cmd = "cp $< $@",
9498
)
9599

100+
# See comment for zonejs above
101+
genrule(
102+
name = "copy_material_theme",
103+
srcs = ["@npm//node_modules/@angular/material:prebuilt-themes/deeppurple-amber.css"],
104+
outs = ["deeppurple-amber.css"],
105+
cmd = "cp $< $@",
106+
)
107+
96108
load("@build_bazel_rules_nodejs//:defs.bzl", "history_server")
97109

98110
history_server(
99111
name = "prodserver",
100112
data = [
101113
"index.html",
102114
":bundle",
115+
":copy_material_theme",
103116
":copy_systemjs",
104117
":copy_zonejs",
105118
],

src/app.component.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
<nav><a routerLink="/">Home</a> | <a routerLink="/todos">Todos</a></nav>
1+
<mat-toolbar>
2+
<nav><a routerLink="/">Home</a> | <a routerLink="/todos">Todos</a></nav>
3+
</mat-toolbar>
24
<router-outlet></router-outlet>

src/app.module.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11

22
import {NgModule} from '@angular/core';
33
import {BrowserModule} from '@angular/platform-browser';
4+
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
45
import {StoreModule} from '@ngrx/store';
56

67
import {AppRoutingModule} from './app-routing.module';
78
import {AppComponent} from './app.component';
9+
import {MaterialModule} from './material/material.module';
810
import {todoReducer} from './reducers/reducers';
911

1012
@NgModule({
1113
declarations: [AppComponent],
12-
imports: [BrowserModule, AppRoutingModule, StoreModule.forRoot({todoReducer})],
14+
imports: [
15+
AppRoutingModule, BrowserModule, BrowserAnimationsModule, MaterialModule,
16+
StoreModule.forRoot({todoReducer})
17+
],
1318
exports: [AppComponent],
1419
bootstrap: [AppComponent],
1520
})

src/hello-world/BUILD.bazel

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ ng_module(
2020
":hello-world.component.html",
2121
":hello-world-styles",
2222
],
23+
tsconfig = "//src:tsconfig.json",
2324
deps = [
2425
"//src/lib",
26+
"//src/material",
2527
"@angular//packages/core",
2628
"@angular//packages/forms",
2729
"@angular//packages/router",
28-
"@npm//@types",
2930
],
3031
)
3132

@@ -38,6 +39,7 @@ ts_library(
3839
"@angular//packages/core",
3940
"@angular//packages/core/testing",
4041
"@angular//packages/platform-browser",
42+
"@angular//packages/platform-browser/animations",
4143
"@angular//packages/platform-browser-dynamic/testing",
4244
"@npm//@types/jasmine",
4345
"@npm//@types/node",
@@ -51,6 +53,7 @@ ts_web_test_suite(
5153
bootstrap = [
5254
"@npm//node_modules/zone.js:dist/zone-testing-bundle.js",
5355
"@npm//node_modules/reflect-metadata:Reflect.js",
56+
"//src:module-id.js",
5457
],
5558
browsers = [
5659
"@io_bazel_rules_webtesting//browsers:chromium-local",

src/hello-world/hello-world.component.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ <h1>Home</h1>
22

33
<div>Hello {{ name }}</div>
44

5-
<input type="text" [(ngModel)]="name"/>
5+
<mat-form-field><input matInput [(ngModel)]="name"/></mat-form-field>
6+
7+
<div><mat-icon>mood</mat-icon></div>

src/hello-world/hello-world.component.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
22
import {By} from '@angular/platform-browser';
33
import {BrowserDynamicTestingModule, platformBrowserDynamicTesting} from '@angular/platform-browser-dynamic/testing';
4+
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
45

56
import {HelloWorldComponent} from './hello-world.component';
67
import {HelloWorldModuleNgSummary} from './hello-world.module.ngsummary';
@@ -21,6 +22,7 @@ describe('BannerComponent (inline template)', () => {
2122
TestBed.configureTestingModule({
2223
declarations: [HelloWorldComponent], // declare the test component
2324
aotSummaries: HelloWorldModuleNgSummary,
25+
imports: [BrowserAnimationsModule],
2426
});
2527
TestBed.compileComponents();
2628
}));

src/hello-world/hello-world.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import {NgModule} from '@angular/core';
22
import {FormsModule} from '@angular/forms';
33
import {RouterModule} from '@angular/router';
4+
import {MaterialModule} from '../material/material.module';
45

56
import {HelloWorldComponent} from './hello-world.component';
67

78
@NgModule({
89
declarations: [HelloWorldComponent],
910
imports: [
10-
FormsModule, RouterModule, RouterModule.forChild([{path: '', component: HelloWorldComponent}])
11+
FormsModule, RouterModule, MaterialModule,
12+
RouterModule.forChild([{path: '', component: HelloWorldComponent}])
1113
],
1214
exports: [HelloWorldComponent],
1315
})

src/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<head>
55
<title>Angular Bazel Example</title>
66
<base href="/">
7+
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
8+
<link href="/deeppurple-amber.css" rel="stylesheet">
79
</head>
810
<body>
911
<!-- The Angular application will be bootstrapped into this element. -->

src/material/BUILD.bazel

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
load("@angular//:index.bzl", "ng_module")
4+
5+
ng_module(
6+
name = "material",
7+
srcs = glob(["*.ts"]),
8+
tsconfig = "//src:tsconfig.json",
9+
deps = [
10+
"@angular//packages/core",
11+
"@angular_material//src/lib:material",
12+
],
13+
)

src/material/material.module.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {NgModule} from '@angular/core';
2+
import {MatButtonModule, MatFormFieldModule, MatIconModule, MatInputModule, MatToolbarModule} from '@angular/material';
3+
4+
const matModules =
5+
[MatButtonModule, MatInputModule, MatFormFieldModule, MatIconModule, MatToolbarModule];
6+
7+
@NgModule({
8+
imports: matModules,
9+
exports: matModules,
10+
})
11+
export class MaterialModule {
12+
}

src/module-id.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Work-around for angular material issue with ts_devserver and ts_web_test_suite.
2+
// Material requires `module.id` to be valid. This symbol is valid in the production
3+
// bundle but not in ts_devserver and ts_web_test_suite.
4+
// See https://github.com/angular/material2/issues/13883.
5+
// TODO(gmagolan): remove this work-around once #13883 is resolved.
6+
var module = {id: ''};

src/todos/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@ ng_module(
2020
"todos.component.html",
2121
":todos-styles",
2222
],
23+
tsconfig = "//src:tsconfig.json",
2324
deps = [
2425
"//src/lib",
26+
"//src/material",
2527
"//src/reducers",
2628
"@angular//packages/common",
2729
"@angular//packages/core",
2830
"@angular//packages/forms",
2931
"@angular//packages/router",
3032
"@npm//@ngrx/store",
31-
"@npm//@types",
3233
"@rxjs",
3334
],
3435
)

src/todos/todos.component.html

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
<h1>Todos</h1>
22

3-
<input placeholder="your todo" [(ngModel)]="todo">
3+
<mat-form-field><input matInput placeholder="your todo" [(ngModel)]="todo"></mat-form-field>
44

5-
<button
5+
<button mat-raised-button color="primary"
66
(click)="addTodo(todo)"
7-
[disabled]="!todo"
7+
[disabled]=!todo
88
*ngIf="!editing">
99
Add todo
1010
</button>
1111

12-
<button
12+
<button mat-raised-button
1313
(click)="updateTodo(todo)"
1414
*ngIf="editing">
1515
Update
1616
</button>
17-
<button
17+
18+
<button mat-raised-button color="warn"
1819
(click)="cancelEdit()"
1920
*ngIf="editing">
2021
Cancel
@@ -23,8 +24,8 @@ <h1>Todos</h1>
2324
<ul>
2425
<li *ngFor="let todo of todos$ | async; let i = index;">
2526
<span [class.done]="todo.done">{{ todo.value }}</span>
26-
<button (click)="editTodo(todo, i)">Edit</button>
27-
<button (click)="toggleDone(todo, i)">Toggle Done</button>
28-
<button (click)="deleteTodo(i)">X</button>
27+
<button mat-raised-button (click)="editTodo(todo, i)">Edit</button>
28+
<button mat-raised-button (click)="toggleDone(todo, i)">Toggle Done</button>
29+
<button mat-raised-button color="warn" (click)="deleteTodo(i)">X</button>
2930
</li>
3031
</ul>

src/todos/todos.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import {CommonModule} from '@angular/common';
22
import {NgModule} from '@angular/core';
33
import {FormsModule} from '@angular/forms';
44
import {RouterModule} from '@angular/router';
5+
import {MaterialModule} from '../material/material.module';
56

67
import {TodosComponent} from './todos.component';
78

89
@NgModule({
910
declarations: [TodosComponent],
1011
imports: [
11-
CommonModule, FormsModule, RouterModule,
12+
CommonModule, FormsModule, RouterModule, MaterialModule,
1213
RouterModule.forChild([{path: '', component: TodosComponent}])
1314
],
1415

0 commit comments

Comments
 (0)