script not running in templateurl

前端 未结 2 1996
迷失自我
迷失自我 2021-01-22 02:46

This is my angular js file

test.js file:

var app = angular.module(\"angleapp\", [])
.controller(\'MainController\', [\'$scope\', function ($scope) {
             


        
相关标签:
2条回答
  • 2021-01-22 03:25

    In partials html page(test.html), No need to write doctype, head and body tags. Just write your html elements and script. It should work.

    0 讨论(0)
  • 2021-01-22 03:41

    The problem is that script tags are not executed by browser automatically when injected with innerHTML (what happens in case of templateUrl). Normally this tags are evaluated programmatically (eval). jQuery does it but jqLite (internal jQuery-like implementation of Angular) does not.

    In your case the fix is simple, move jquery script tag before angular, then Angular will use jQuery for DOM manipulations:

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
    

    Also, you need to clean up your test.html template, leave only body content. This is how test.html should look:

    hi how are you
    
    <script type="text/javascript">
        alert("stop");
    </script>
    

    And finally, I don't know why you need to have script tag inside of partial template, but in most cases this is bad idea, and there are better approaches.

    0 讨论(0)
提交回复
热议问题