Angular.js范围原始值 - 缩短功能?

时间:2014-08-20 16:29:04

标签: angularjs

我的范围内有原始值,我想知道是否有更好的方法来处理这些值并缩短我看起来臃肿的功能。

angular.module('main.loadbalancer').controller('CreateNodeCtrl', function($scope, $modalInstance, LoadBalancerService, StatusTrackerService, NodeService) {
  $scope.createNode = function(node) {
    var TIME_CLOSE_MODAL;
    TIME_CLOSE_MODAL = 3000;
    $scope.disableButtonsForRun = false;
    $scope.statusBar = true;
    $scope.nodeStatus = 'Building';
    $scope.statusType = 'warning';
    return LoadBalancerService.getLoadBalancer().then(function(loadBalancer) {
      return NodeService.createNode({
        account_number: loadBalancer.customer,
        admin_state: 'enabled',
        label: node.label,
        ip: node.ip,
        port: node.port,
        comment: node.comment,
        health_strategy: {},
        vendor_extensions: {}
      }).then(function(eventId) {
        trackStatus = void 0;
        $scope.disableButtonsForRun = true;
        StatusTrackerService.runEventCheck(loadBalancer.customer, eventId)
        .then(function() {
          $scope.statusType = 'success';
          $scope.nodeStatus = 'Completed Successfully';
          setTimeout((function() {
            $modalInstance.close();
          }), TIME_CLOSE_MODAL);
        }, function() {
          $scope.nodeStatus = 'Failure!';
          $scope.statusType = 'danger';
        })['finally'](function() {
          $scope.disableButtonsForRun = false;
        });
      });
    });
  };
  $scope.node = {
    keepaliveType: 'TCP',
    keepaliveMethod: 'GET'
  };
  $scope.close = function() {
    $scope.nodeStatus = 'Building';
    $scope.statusType = 'warning';
    $modalInstance.close();
  };});

<div class="modal-footer">
  <div ng-if="statusBar">
    <div class="row">
      <progressbar animate="false" class="progress-striped active"  value="100" type="{{statusType}}">{{nodeStatus}}</progressbar>
    </div>
  </div>
  <div ng-switch on="disableButtonsForRun">
    <div ng-switch-when="true">
      <button type="button" class="btn btn-default"  ng-disabled="true" ng-click="close()">Cancel</button>
      <button type="button" class="btn btn-primary" ng-click="createNode($parent.node)" ng-disabled="true">Create</button>
    </div>
    <div ng-switch-default>
      <button type="button" class="btn btn-default" ng-click="close()">Cancel</button>
      <button type="button" class="btn btn-primary" ng-click="createNode($parent.node)" ng-disabled="form.$invalid || !form.$dirty">Create</button>
    </div>
  </div>
</div>
</form>

0 个答案:

没有答案