NNR*_*NNR 11 javascript twitter-bootstrap angularjs
我在加载内容时使用按钮微调器,当用户点击"搜索"按钮时会加载内容,此时buttonLabel将更改为"搜索"并显示微调器(此处按钮将被禁用).加载后内容(Promise已解决)buttonLabel将恢复为"搜索"(此处将启用按钮).
我尝试了下面的代码,但它始终显示微调器.
HTML:
<button class="btn btn-xs btn btn-blue" ng-click="show()">
<span><i class="glyphicon glyphicon-off"></i></span> {{buttonLabel}}
</button>
Run Code Online (Sandbox Code Playgroud)
脚本:
$scope.buttonLabel = "Search";
$scope.show = function() {
$scope.buttonLabel = "Searching";
$scope.test = TestService.getList( $cookieStore.get('url'),
$rootScope.resourceName+"/students" );
$scope.test.then( function( data ) {
if( data.list ) {
$scope.testData = data.list;
$scope.buttonLabel = "Search";
}
}
}
Run Code Online (Sandbox Code Playgroud)
更新小提琴: http ://jsfiddle.net/xc6nx235/18/
Jag*_*ngh 13
<div ng-app="formDemo" ng-controller="LocationFormCtrl">
<div>
<button type="submit" class="btn btn-primary" ng-click="search()">
<span ng-show="searchButtonText == 'Searching'"><i class="glyphicon glyphicon-refresh spinning"></i></span>
{{ searchButtonText }}
</button>
</div>
Run Code Online (Sandbox Code Playgroud)
您需要做的就是使用ng-show或ng-hide指令.
NG-节目= "表达"
<span ng-show="searchButtonText == 'Searching'">
<i class="glyphicon glyphicon-refresh spinning"></i>
</span>
Run Code Online (Sandbox Code Playgroud)
只有在searchButtonText字符串'Searching' 时才会显示此范围.
您应该了解有关angular指令的更多信息.它们将来会很有用.
祝好运.
演示http://jsfiddle.net/xc6nx235/16/
使用ng-show显示(或不)装载机ng-show="test":
// http://icelab.com.au/articles/levelling-up-with-angularjs-building-a-reusable-click-to-edit-directive/
angular.module("formDemo", [])
.controller("LocationFormCtrl", function ($scope, $timeout) {
$scope.searchButtonText = "Search";
$scope.test="false";
$scope.search = function() {
$scope.test="true";
$scope.searchButtonText = "Searching";
$timeout(function(){
$scope.test="false";
$scope.searchButtonText = "Search";
},1000)
// Do your searching here
}
});Run Code Online (Sandbox Code Playgroud)
body {
font-family:"HelveticNeue", sans-serif;
font-size: 14px;
padding: 20px;
}
h2 {
color: #999;
margin-top: 0;
}
.field {
margin-bottom: 1em;
}
.click-to-edit {
display: inline-block;
}
input {
display: initial !important;
width: auto !important;
margin: 0 5px 0 0 !important;
}
.glyphicon.spinning {
animation: spin 1s infinite linear;
-webkit-animation: spin2 1s infinite linear;
}
@keyframes spin {
from { transform: scale(1) rotate(0deg);}
to { transform: scale(1) rotate(360deg);}
}
@-webkit-keyframes spin2 {
from { -webkit-transform: rotate(0deg);}
to { -webkit-transform: rotate(360deg);}
}Run Code Online (Sandbox Code Playgroud)
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/foundation/4.1.6/css/foundation.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<script src="https://rawgithub.com/angular-ui/angular-ui/master/build/angular-ui.js"></script>
<div ng-app="formDemo" ng-controller="LocationFormCtrl">
<div>
<button type="submit" class="btn btn-primary" ng-click="search()">
<span ng-show="test" ><i class="glyphicon glyphicon-refresh spinning"></i></span>
{{ searchButtonText }}
</button>
</div>
</div>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
51382 次 |
| 最近记录: |