I have these files:
index.html
//contains logic about passing arguments to the app.js btnClick function
<div ng-bind-html="currentDisplay"></div>
app.js
app.factory('oneFac', function ($http){
var htmlCode = null;
htmlCode = $http.get("one.html").then(function (response){
return response.data;
});
return htmlCode;
});
app.factory('twoFac', function ($http){
var htmlCode = null;
htmlCode = $http.get("two.html").then(function (response){
return response.data;
});
return htmlCode;
});
app.controller('mainCtrl', function ($scope, oneFac, twoFac, $sce){
$scope.one = oneFac;
$scope.two = twoFac;
$scope.currentDisplay = $sce.trustAsHtml($scope.one);
$scope.btnClick = function (selection){
if(selection == "one"){
$scope.currentDisplay = $sce.trustAsHtml($scope.one);
}
else if(selection == "two"){
$scope.currentDisplay = $sce.trustAsHtml($scope.two);
}
}
});
one.html
<p>one</p>
two.html
<p>two</p>
How could I get the HTML into the $scope then have it inserted into the html?
I am getting an error saying $sce requires a string argument, but I thought what I am passing to it should be a string.
ng-bind-htmlorng-includeif you only need to load html files