Javascript not accessible from inside Angular ui-view

前端 未结 7 1543
执念已碎
执念已碎 2021-01-18 17:56

I have a main template (index.html) with an Angular ui-view. Inside this main template I import a bunch of Javascript files. I expect these files to be available to the cont

相关标签:
7条回答
  • 2021-01-18 18:55

    This is a super late response, but I ran into this same exact issue myself. I have solved this by including the external js libraries before including Angular and Angular UI Router.

    Just like the OP, my project consisted of an index.html as well as a ui-view. The partials load into the ui-view properly, but the external js libraries do not take effect inside the partial via ui-view. If the contents from the partial are placed into the index.html, everything works perfectly.

    Scripts changed from

    <!-- AngularJS -->
    <script type="text/javascript" src="node_modules/angular/angular.min.js"></script>
    <script type="text/javascript" src="node_modules/angular-ui-router/release/angular-ui-router.min.js"></script>
    <script src="dist/components.js" type="text/javascript"></script>
    
    <!-- Custom JS Libries -->
    <script src="dist/js/custom.js" type="text/javascript"></script>  
    

    Scripts changed to

    <!-- Custom JS Libries -->
    <script src="dist/js/custom.js" type="text/javascript"></script>
    
    <!-- AngularJS -->
    <script type="text/javascript" src="node_modules/angular/angular.min.js"></script>
    <script type="text/javascript" src="node_modules/angular-ui-router/release/angular-ui-router.min.js"></script>
    <script src="dist/components.js" type="text/javascript"></script> 
    

    Final Outcome and working

    <!DOCTYPE html>
    <html dir="ltr" data-config='{"style": "calico"}'>
    <head>
        <link rel="stylesheet" href="dist/all.css">
    </head>
    
    <body ng-app="MyApp">
    
        <div ui-view></div>
    
        <!-- Custom JS Libries -->
        <script src="dist/js/custom.js" type="text/javascript"></script>
    
        <!-- AngularJS -->
        <script type="text/javascript" src="node_modules/angular/angular.min.js"></script>
        <script type="text/javascript" src="node_modules/angular-ui-router/release/angular-ui-router.min.js"></script>
        <script src="dist/components.js" type="text/javascript"></script> 
    
    </body>
    </html>
    
    0 讨论(0)
提交回复
热议问题