Created
June 20, 2014 11:54
-
-
Save cpoDesign/db73f685ddf275d7d9c7 to your computer and use it in GitHub Desktop.
AngularJS - Loading content from file with Html and javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = angular.module('app', []); | |
app.controller('testCtr', | |
function priorityCtr($scope, myService, $sce){ | |
myService.getData('dataSource.html').then(function(response){ | |
$scope.data = $sce.trustAsHtml(response); | |
}); | |
}); | |
app.factory('myService', function($http, $q) { | |
return { | |
getData: function(path) { | |
var deferred = $q.defer(); | |
$http.get(path).then(function(response) { | |
deferred.resolve(response.data); | |
}); | |
return deferred.promise; | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p> | |
<script type="text/javascript">// <![CDATA[ | |
$(document).ready(function(){ | |
$(".ContentLink").click(function(){ | |
$(this).parent().next(".TextContent").slideToggle(); | |
return false; | |
}); | |
}); | |
// ]]></script> | |
</p> | |
<p>Use the links below to show content.</p> | |
<h3><a href="#" class="ContentLink">Link</a></h3> | |
<div class="TextContent" style="display: none;"> | |
<ul> | |
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc sagittis nunc id nulla commodo blandit. Pellentesque dictum felis sem, et convallis nulla consequat nec. Vivamus luctus lorem ut arcu pulvinar tempus vel mollis metus. Duis pulvinar consequat sagittis. Cras volutpat pretium ligula, eget molestie arcu eleifend nec. Vivamus nulla sapien, placerat eu leo sed, molestie mattis nisl. Ut metus quam, condimentum ac lectus eget, tincidunt suscipit ligula. Vestibulum id dignissim ipsum. Ut ultricies gravida ipsum id adipiscing.</li> | |
</ul> | |
</div> | |
<h3><a href="#" class="ContentLink">Link</a></h3> | |
<div class="TextContent" style="display: none;"> | |
<ul> | |
<li>Nunc malesuada, velit id semper commodo, sem felis tempus urna, ornare lobortis mi est ac mi. Praesent tincidunt commodo vehicula. Donec lorem quam, faucibus et consectetur quis, aliquam venenatis arcu. Duis posuere neque est, nec pharetra nisi luctus ut. Nullam vel lacus eleifend quam dapibus vehicula. Phasellus malesuada ac tortor mollis bibendum. Quisque laoreet porta tincidunt. Proin consequat convallis sapien.</li> | |
</ul> | |
</div> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html ng-app="app"> | |
<head> | |
<script src="//code.jquery.com/jquery-latest.min.js"></script> | |
<script src="../js/angular.js" type="application/javascript"></script> | |
<script src="app.js"></script> | |
</head> | |
<body ng-controller="testCtr"> | |
<p> | |
I am using angular 1.2.16 | |
</p> | |
<div ng-bind-html="data"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment