문제

I'm trying to pull a crazy trick and I am kinda stuck.

What I need to do is to use angular on AppleTV. What's the purpose of using angular on something that doesn't have DOM at all? I'm trying to reuse bunch of angular services, written for another app, so I need to use serviceProvider part of angular and its dependency injection mechanism. I probably could use node-di for dependency, probably that still wouldn't solve serviceProvider part.

Generally what I need to be able to do is to load angular.js code (maybe via XHR) and eval it. Currently I wasn't able to do it, angular has tons of dependencies on DOM objects. I tried loading angular, using jsdom, it worked on node, but didn't on AppleTV. Jsdom by itself too coupled with node.

도움이 되었습니까?

해결책

I was able to eval it by mocking out all DOM dependencies

  Location = ->
  Location.prototype.href = ""
  Location.prototype.pathname = ""

  Window = ->
  Window.prototype.location = new Location()
  Window.prototype.addEventListener =  ->
  window = new (Window)
  global.window = window

  Element = ->
  Element.prototype.setAttribute = ->
  Element.prototype.pathname = ""
  Element.prototype.addEventListener = ->
  Element.prototype.find =-> new Element()

  Document = ->
  Document.prototype.createElement = -> new Element
  Document.prototype.addEventListener = ->
  document = new Document()
  global.document = document

  window.document = document
  Navigator = ->
  navigator = new Navigator()
  global.navigator = navigator
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top