ボタンをクリックして変数をフォームに置き換えたい。どうすればいいですか?
JavaScript
var MainCtrl = angular.module('mainCtrl', []);
MainCtrl.controller('MainCtrl', function ($scope) {
$scope.bar = 'Foo';
$scope.foo = function(){
$scope.bar = '<form class="form-inline" role="form"> <div class="form-group"> <label class="sr-only" for="exampleInputEmail2">Email address</label> <input type="email" class="form-control" id="exampleInputEmail2" placeholder="Enter email"> </div> <div class="form-group"> <label class="sr-only" for="exampleInputPassword2">Password</label> <input type="password" class="form-control" id="exampleInputPassword2" placeholder="Password"> </div> <div class="checkbox"> <label> <input type="checkbox"> Remember me </label> </div> <button type="submit" class="btn btn-default">Sign in</button> </form>';
}
});
var fooApp = angular.module(
'fooApp', ['ngSanitize', 'mainCtrl'];
);
HTML
<body ng-app='fooApp' ng-controller="MainCtrl">
<div ng-bind-html="bar"></div>
<button class="btn" ng-click="foo()">Change bar to form</button>
</body>