Search code examples
javascriptangularjsionic-frameworkinnerhtmlng-bind-html

Angular JS Inner Html for Ionic Framework


I am developing my application with angularjs and ionic,

<div ng-app="myApp" ng-controller="myCtrl">

    <p ng-bind-html="{{itemID}}"></p>

</div>

I would like to change this to angularjs like innerHTML,

<script>
var app = angular.module("myApp", ['ngSanitize']);
app.controller("myCtrl", function($scope) {
    $scope.myText = "My name is:John Doe";
});
</script>

This is not because it needs to write itemid instead of $scope.myText.

How can I do it uniquely as above ?


Solution

  • I solved the problem. controller.js

    $scope.myText={};
    
    
        var app = angular.module("myApp", ['ngSanitize']);
        app.controller("myCtrl", function($scope,$itemID) {
            $scope.myText{$itemID} = "My name is:John Doe";
        });
    

    html page

    <div ng-app="myApp" ng-controller="myCtrl">
        <p ng-bind-html="myText[$itemID]"></p>
    </div>