epv epv - 4 months ago 9
HTML Question

How to include a script into my cshtml file without all the script texts

I have a asp.net cshtml file but I have to include script html's with ids for my ngRoutes to work. So far my cshtml file looks like this:

<div ng-view></div>

<script type="text/ng-template id="one.html">
...very long html...
</script>
<script type="text/ng-template id="two.html">
...very long html...
</script>
<script type="text/ng-template id="three.html">
...very long html...
</script>
<script type="text/ng-template id="four.html">
...very long html...
</script>


I don't want to include all the script, but need it to display like a directive. How am I able to do something like...

<div ng-view></div>
<div ng-include="'one.html''"></div>
<div ng-include="'two.html''"></div>
<div ng-include="'three.html''"></div>


I've tried that way but it doesn't allow me to just include it in the razor file.

Answer

I assume you're using ngRoute. In this case you can set the template urls on the routeProvider during the config phase:

angular.module('yourmodule', ['ngRoute'])
.config(['$routeProvider', function ($routeProvider) {
    $routeProvider
        .when('/one', {
            templateUrl: 'one.html',
        })
        .when('/two', {
            templateUrl: 'two.html',
        });
}])