Created
April 7, 2017 22:05
-
-
Save darzo27/535a40b8d52aded49942701e6c651f74 to your computer and use it in GitHub Desktop.
Angular 2 HTML binding using expressions. View on JSFiddle: https://jsfiddle.net/DARZO27/01q4jeht/2/
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
<!--View on JSFiddle: https://jsfiddle.net/DARZO27/01q4jeht/2/--> | |
<html> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-sanitize.js"></script> | |
<body> | |
<div ng-app="myApp" ng-controller="myCtrl"> | |
<p ng-bind-html="myText"></p> | |
<p>My name is <span ng-bind-html="myName"></span><p> | |
<p> Position:<span ng-bind-html="myPosition"></span></p> | |
</div> | |
<script> | |
var app = angular.module("myApp", ['ngSanitize']); | |
app.controller("myCtrl", function($scope) { | |
$scope.myText = "<h1>Leaderboard</h1><hr width='80%' size='5' color='#000000'>"; | |
$scope.myName = "<h2>Jane Doe</h2>"; | |
$scope.myPosition = "<h1>1<sup>st</sup><h1>"; | |
}); | |
</script> | |
<p><b>Note:</b> This example includes the "angular-sanitize.js", | |
which has functions for removing potentially dangerous tokens from the HTML. - w3 | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment