0

I'm very newbie to angularjs, and I followed the script document of angularjs to created a very simple script tag of template, however it does't work at all, below is the code and JSFIDDLE.

<div ng-app>   
    <table>
        <ng-include src="tpl.html"></ng-include>
    </table>
    <div ng-include src="tpl2.html"></div>

    <script type="text/ng-template" id="tpl.html">
        <tr>
            <td>ACBC</td>
        </tr>
    </script>

    <script type="text/ng-template" id="tpl2.html">
        test
    </script>
</div>

Any problem with my code?

1
  • 1
    ng-include's src is angular expression evaluating to URL. If the source is a string constant, you have to wrap it in single quotes, Commented May 25, 2015 at 9:36

2 Answers 2

1

put the url in single quotes

src="'tpl.html'"

`

<script type="text/ng-template" id="tpl.html">
    <tr>
        <td>ACBC</td>
    </tr>
</script>

<script type="text/ng-template" id="tpl2.html">
    test
</script>

see fiddle update `http://jsfiddle.net/U3pVM/15840/

Sign up to request clarification or add additional context in comments.

1 Comment

I see, but I encountered another problem see the updated fiddle Inline Link, I'd like to repeat that included template, it seems doesn't work either.
0

You missed <td></td> element :) This is how you should implement your code

<div ng-app>
<table>
   <tr ng-repeat="i in [1,2,3,4,5,6]">                     
       <td>
           <ng-include src="'tpl.html'"></ng-include>
       </td>          
   </tr>
</table>

<div ng-include src="'tpl2.html'"></div>

<script type="text/ng-template" id="tpl.html">
        <td>ACBC</td>
</script>
<script type="text/ng-template" id="tpl2.html">
    test
</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.