简体   繁体   English

angularjs指令未加载

[英]angularjs directive is not loading

i tried to implement turn.js in angularjs app, when i click a link it takes to the page having that turn.js at that time my custom directive is not loading. 我试图在angularjs应用中实现turn.js,当我单击一个链接时,该链接指向当时没有加载我的自定义指令的页面。 If i press F5 then the custom directive is loading and turn.js is working propely. 如果我按F5键,则自定义指令正在加载并且turn.js正常工作。

My custom directive is like this 我的自定义指令是这样的

app.directive "turnJs", ->
  alert "loaded"
  restrict: "A"
  link: (scope, element, attrs) ->
    $(element).turn scope.$eval(attrs.turnJs)
    return

and my view is like this 我的看法是这样的

<div class="butiknamncontainer" id="magazine" turn-js>
  <div>
    dfdssdfs
  </div>
  <div>
    sdffsdfsf
  </div>
</div>

is there any way to load the directive while doing that ng-click?? 有什么办法可以在执行ng-click时加载指令?

You need to include the directive definition one the first page of your app so that Angular knows what to do when it encounters the directive in your HTML. 您需要在应用程序的第一页中包含指令定义,以便Angular知道在HTML中遇到指令时该怎么做。

The reason it works when you refresh is because Angular is being bootloaded along with the directive definition(Look at the hashtag in the URL). 刷新时它起作用的原因是,Angular随指令定义一起引导加载(请查看URL中的井号标签)。

Whereas when Angular is bootloaded without that file, such as when there is nothing in your hashtag, Angular has no idea what to do when it later encounters that directive. 而在没有该文件的情况下启动Angular时(例如,您的标签中没有任何内容),Angular不知道以后遇到该指令时该怎么做。 So, it gets ignored. 因此,它被忽略。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM