-
Notifications
You must be signed in to change notification settings - Fork 1
/
core.cljs
51 lines (30 loc) · 1.24 KB
/
core.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
(ns cljs-angular2.core
(:require-macros [hiccups.core :as hiccups :refer [html]])
(:require
[goog.events :as events]
[goog.history.EventType :as HistoryEventType]
[markdown.core :refer [md->html]]
[ajax.core :refer [GET POST]])
(:import goog.History))
(defn get-app []
(or (.-app js/window)
(set! (.-app js/window) #js {})))
(defonce heroes (atom []))
(let [app (get-app)
c (.Component (.-core js/ng)
#js {:selector "my-app"
:template (html [:div
[:h1 " Demo"]
[:div [:h2 "Hero List:"]]
"
<input #newHero (keyup.enter)=\"addHero(newHero.value); newHero.value='' \" >
<button (click)=\"addHero(newHero.value); newHero.value='' \">Add</button>
<ul><li *ngFor=\"#hero of heroes()\">{{hero}}</li></ul>
"
])})
c (.Class c #js {:constructor (fn [])
:addHero (fn [hero]
(swap! heroes #(conj % hero)))
:heroes (fn [] @heroes)
})]
(set! (.-AppComponent app) c))