如何从模板html文件中获取innerHtml?
赞mainform.innerHtml = 'template.html'
var myApp = angular.module('myApp', []);
myApp.controller('myCtrl', function ($scope) {
$scope.myfunction = function () {
var text_1 = document.getElementById('text_1').value;
var mainform = document.getElementById('mainform');
if (text_1 == 's') {
mainform.innerHTML = '<p>sala</p>'
}
else {
alert("error");
}
}
});
答案 0 :(得分:1)
试试这个http://plnkr.co/edit/V3uNa24QkSj6XRODB3R0?p=preview
<body ng-controller="MainCtrl">
<button ng-click="changeTemplate('template1.html')">Template 1</button>
<button ng-click="changeTemplate('template2.html')">Template 2</button>
<div ng-include="template"></div>
</body>
控制器:
app.controller('MainCtrl', function($scope) {
$scope.template = 'template1.html';
$scope.changeTemplate = function(template){
$scope.template = template;
}
});
template1.html
<div>Template 1</div>