search

Home  >  Q&A  >  body text

Different pages introduce js problems during angular.js routing

Using ng as a framework, I found a problem when routing. It doesn't work when different pages use different js. I know the reason is that your js needs to get some Dom nodes. But when the homepage is first loaded, my page is not loaded. At this time, these DOM nodes cannot be obtained. Do you have any good solutions?

迷茫迷茫2807 days ago540

reply all(4)I'll reply

  • 滿天的星座

    滿天的星座2017-05-15 17:04:39

    The DOM event cannot take effect. There is a live method (jquery on). If the double binding of data fails, $scope.$apply() is manually refreshed. The loading of the DOM node is also related to the location where your js is written. Your question is not clear enough

    reply
    0
  • 滿天的星座

    滿天的星座2017-05-15 17:04:39

    A frequently used method, use the $timeout method:

    $timeout(function() {
        // TODO
        // 这里填写你的功能代码
    }, 1000) // 这个时间你可以自己选择

    reply
    0
  • 给我你的怀抱

    给我你的怀抱2017-05-15 17:04:39

    angular.element(document).ready()
    Put js in ready and try it

    reply
    0
  • 滿天的星座

    滿天的星座2017-05-15 17:04:39

    This problem has been solved. I also encountered it before and struggled with it for a long time. http://www.weipxiu.com/?p=434

    reply
    0
  • Cancelreply