Angularjs Theater.js在加载了Angular ui路由的页面上不工作

Angularjs Theater.js在加载了Angular ui路由的页面上不工作,angularjs,Angularjs,我正试图用角度的应用来做工作 如果TheaterJS应该在其中插入动态类型内容的Div位于索引页上,那么它工作得非常好 但是,如果我在使用ui视图(或者使用ng视图)加载的页面上保留相同的div,TheaterJs会抛出以下异常 Uncaught TypeError: Cannot set property 'innerHTML' of null 我理解它的发生,因为TheaterJs是在main.html页面通过ui视图加载之前加载的。但我不知道如何处理这种情况 下面是示例的示例。The

我正试图用角度的应用来做工作

如果TheaterJS应该在其中插入动态类型内容的Div位于索引页上,那么它工作得非常好

但是,如果我在使用ui视图(或者使用ng视图)加载的页面上保留相同的div,TheaterJs会抛出以下异常

Uncaught TypeError: Cannot set property 'innerHTML' of null  
我理解它的发生,因为TheaterJs是在main.html页面通过ui视图加载之前加载的。但我不知道如何处理这种情况

下面是示例的示例。TheaterJS在div位于索引页时工作,但在div位于main.html上时无法工作,main.html使用ui视图动态加载


在我的项目中,我想在使用ui视图加载的页面上使用TheaterJS。

通过将脚本include放入
并将对
new TheaterJS()
的调用移动到指令中,您可以在部分中使用它

下面是一个plunker,显示您的工作模板:

指令:

app.directive("theaterDirective", function() {
  return {
    link: function () {
      var theater = new TheaterJS();
      theater.describe("text", {speed: .7, accuracy: .7}, "#text");
      theater.write("text:It now works in template partials", 600);
      theater.write("text:It is no longer restricted to the Index page", 600);
      theater.write(function () { theater.play(true); }); 

    }
  }
})
HTML部分:

<h1>This is main.html page content</h1>
<h1 theater-directive id="text"><noscript></noscript></h1>
这是main.html页面内容

非常感谢您的帮助。是的,它的工作与链接功能伟大。感谢您的及时帮助:)