Rivka
Rivka

Reputation: 171

Angular2 for clojurescript

I would like to build an application with clojurescript language and angular2 framework.

I've found this project on github which provided a basic exmaple of combining these two. But this is just a basic start, I've had difficulty with declaring new components and adding more of angular2 features into my app.

Are there any tutorials on this issue? Have you tried working with both clojurescipt and angular2?

Thanks for your help

Upvotes: 6

Views: 1753

Answers (1)

Daniel Compton
Daniel Compton

Reputation: 14549

While this is possible to do, you are going to be going quite far off the beaten path. Angular relies heavily on annotations, dependency injection, and Javascript features which is not going to be a great fit for ClojureScript.

Writing Angular like the sample below is going to be very annoying and error-prone:

(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>
"
                                          ])})

If you go down this path, you will mostly end up writing JavaScript in a funny DSL (ClojureScript).

It's probably worth stepping back and asking why you want to use both Angular and ClojureScript? They both have quite distinct philosophies and styles. If you are wanting to use ClojureScript, then there are several good ClojureScript frameworks for building SPA's like Om, re-frame, and rum that take advantage of ClojureScript's strengths like immutable data and functional programming.

Upvotes: 12

Related Questions