0

我有个问题。将我需要的按钮称为“关闭”或“打开”。如果 json 中的活动状态为 1,则按钮关闭显示在 html 中,所以改为。但我试过了

ng-绑定-html

仍然无法正常工作,对我有什么解决方案吗?谢谢

这是我的代码:

控制器

if(item.active === 1){
    html_button = '<button type="button" class="btn btn-success"><i class="fa fa-toggle-on"></i> On</button>';

}else{
   console.log(1);
    html_button = '<button type="button" class="btn btn-default"><i class="fa fa-toggle-off"></i> Off</button>';
}

$scope.getButtonOnOff = function(html_button) {

    return $sce.trustAsHtml(html_button);

};

html

<span ng-if="data.active === 1">
            <button ng-show="data.active" type="button" class="btn btn-default" ng-click="FiturThread(data)"><i class="fa fa-toggle-off"></i> Off</button>
            <button ng-hide="data.active" type="button" class="btn btn-success" ng-click="FiturThread(data)"><i class="fa fa-toggle-on"></i> On</button>
        </span>
        <span ng-if="data.active === 0">
            <button ng-show="data.active" type="button" class="btn btn-success" ng-click="FiturThread(data)"><i class="fa fa-toggle-on"></i> On</button>
            <button ng-hide="data.active" type="button" class="btn btn-default" ng-click="FiturThread(data)"><i class="fa fa-toggle-off"></i> Off</button>
        </span>
4

1 回答 1

2

让我们尝试角度方式

<td width="20%">
        <button type="button" class="btn btn-primary" ng-click="getData(data)"><i class="fa fa-edit"></i> Edit</button>
        <button ng-show="item.active" type="button" class="btn btn-default"><i class="fa fa-toggle-on"></i> On</button>
        <button ng-hide="item.active" type="button" class="btn btn-default"><i class="fa fa-toggle-off"></i> Off</button>
</td>
于 2017-02-18T08:33:29.357 回答