AngularJS ng-bind-html
ညွှန်ကြားချက်
ဥပမာ
<p> ဒြပ်စင်၏ အတွင်း HTML ကို ပြောင်းလဲနိုင်သော myText နှင့် ချိတ်ပါ :
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<script
src="//ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular-sanitize.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<p ng-bind-html="myText"></p>
</div>
<script>
var app =
angular.module("myApp", ['ngSanitize']);
app.controller("myCtrl",
function($scope) {
$scope.myText = "My name is:
<h1>John Doe</h1>";
});
</script>
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
လမ်းညွှန်ချက် သည် ng-bind-html
အကြောင်းအရာကို HTML ဒြပ်စင်တစ်ခုသို့ ချိတ်ဆက်ရန် လုံခြုံသောနည်းလမ်းဖြစ်သည်။
AngularJS ကို သင့်အပလီကေးရှင်းတွင် HTML ရေးခွင့်ပြုသောအခါ၊ အန္တရာယ်ရှိသောကုဒ်အတွက် HTML ကိုစစ်ဆေးသင့်သည်။ သင့်အပလီကေးရှင်းတွင် "angular-sanitize.js" မော်ဂျူးကို ထည့်သွင်းခြင်းဖြင့် ngSanitize လုပ်ဆောင်ချက်မှတစ်ဆင့် HTML ကုဒ်ကို လုပ်ဆောင်ခြင်းဖြင့် သင်သည် ထိုသို့ပြုလုပ်နိုင်သည်။
အထားအသို
<element ng-bind-html="expression"></element>
HTML ဒြပ်စင်များအားလုံးမှပံ့ပိုးထားသည်။
ကန့်သတ်တန်ဖိုးများ
Value | Description |
---|---|
expression | Specifies a variable, or an expression to evaluate. |