jquery - 使用 Angularjs 加载文本的 Bootstrap 按钮

标签 jquery angularjs twitter-bootstrap

在使用 bootstrap 和 jquery 的非 Angular 应用程序中,我可以创建如下按钮:

<button id="saveButton" data-loading-text="Please wait...">Save</button>

然后,当单击按钮时,我可以将其设置为加载状态,如下所示:

$('#saveButton').button('loading');

单击此按钮还会触发 ajax 请求,并且在该请求的回调中,我可以像这样重置按钮:

$('#saveButton').button('reset');

如何在 Angular 应用程序中实现相同的行为?该应用程序还包括 Jquery 和 Bootstrap。

最佳答案

使用data-loading-text的优势就是让 HTML 远离 Controller 。不要在 Controller 函数中交换文本,而是使用 ng-showng-hide按钮内:

<button>
    <span ng-hide="saving">Save</span>
    <span ng-show="saving">Please wait...</span>
</button>

在 Controller 中,设置$scope.saving真或假。

$scope.saving = false;
$scope.save = function() {
    $scope.saving = true;
    // Do your saving here
    $scope.saving = false;
}

如果您想在加载时禁用该按钮,请使用 ng-disabled 。要使用旋转的 FontAwesome 图标,请替换 <span><i>标签如下所示:

 <button ng-disabled="saving">
    <span ng-hide="loading">Save</span>
    <i class="fa fa-spinner fa-spin" ng-show="saving"></i>
</button>

关于jquery - 使用 Angularjs 加载文本的 Bootstrap 按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26170192/

相关文章:

javascript - 随机未定义

javascript - 如何使用 jquery 为 slider 创建缩略图

javascript - 我想使用 angularJs 和 ionic 实现类似于 facebook 的评论部分

javascript - 如何在 td 标签上使用 ng-bind?

javascript - 什么可能导致 Angular 无法正常渲染?

javascript - 视频覆盖的 Bootstrap 导航栏 - 如何用不透明背景覆盖它?

html - 将 1/4 添加到 Twitter Bootstrap 列

jquery - 调整大小时的 float 元素位置 (jQuery/CSS)

javascript - 如果加载事件已经触发,则将加载事件绑定(bind)到 iframe 或运行函数

css - Bootstrap 表半径重置