Reputation: 1621
I'm writing a tutorial website for angularjs using angularjs and I have a lot sections of sample code.
So I have a bunch of <pre><html ng-app></html></pre>
tags.
I want to put the code samples in a separate files but ng-include
doesn't work on <pre></pre>
tags. How would I put html code samples in separate files?
Small side question: what would you name the folder of those files? Would ./samples/
work?
I've tried this solution: https://stackoverflow.com/a/34164921/859082
But it doesn't seem to work because the sample doesn't stay preformatted for newlines and tabs and I don't know why it doesn't work. Here's my attempt using the previous solution: http://plnkr.co/edit/0nP76Im6XWWCleShsxAR?p=preview
Upvotes: 1
Views: 86
Reputation: 5059
I forked your plunker, and came up with this plunker here. You could dynamically set the path, which would update the content.
HTML
<body ng-app="app">
<div ng-controller="mainCtrl">
<pre ng-bind="content"></pre>
</div>
</body>
JS
angular
.module('app', [])
.controller('mainCtrl',function($scope,$http,$log){
$http({
method: 'GET',
url: 'common1.html'
}).then(function successCallback(resp) {
$scope.content = resp.data;
}, function errorCallback(response) {
$log.warn('Could not locate file...');
});
});
Additional Plunks:
Upvotes: 1