我想建立一个应用程序与clojurescript语言和angular2框架。
我在github上找到了this project,它提供了一个将两者结合起来的基本示例。但这只是一个基本的开始,我在声明新组件和在我的应用程序中添加更多angular2功能时遇到了困难。
有没有关于这个问题的教程?你有没有尝试过同时使用clojurescipt和angular2?
谢谢你的帮忙
发布于 2017-03-16 17:16:53
虽然这是可以做到的,但你将会远离常规的道路。Angular在很大程度上依赖于注释、依赖注入和Javascript特性,而这些特性不太适合ClojureScript。
像下面的sample这样写Angular将会非常烦人并且容易出错:
(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>
"
])})如果你沿着这条路走下去,你最终会在一个有趣的领域特定语言(ClojureScript)中编写JavaScript。
这可能值得后退一步,问问你为什么要同时使用Angular和ClojureScript?他们都有截然不同的哲学和风格。如果您想使用ClojureScript,那么有几个很好的ClojureScript框架可以用来构建SPA,比如Om、re-frame和rum,它们利用了ClojureScript的不可变数据和函数式编程等优势。
https://stackoverflow.com/questions/42829156
复制相似问题