angularjs ui tab + post request

时间:2014-10-15 08:08:46

标签: angularjs

我在html上有简单的 angularjs 标签,我想将数据发布到基于休息的api。 我的查询是如何从制表符获取控件值并将其发布到基于休息的api 这是我的代码......

我已经厌倦了几个例子来获得标签,但没有成功。



validationApp.controller('TabsCtrl', function($scope, $http, $location, $window, $routeParams) {
          var headerValue = $routeParams.auth;
          alert(headerValue);
          $scope.tabs = [{
              title: 'Upload Configuration',
              url: 'upload.tab.html'
            }
          ];
           $scope.currentTab = 'upload.tab.html';
            $scope.onClickTab = function(tab) {
            $scope.currentTab = tab.url;
          }
         $scope.isActiveTab = function(tabUrl) {
            return tabUrl == $scope.currentTab;
          }
          $scope.uploadFile = function(vmUploadme, myName) {
            var fd = new FormData();
            //Take the first selected file
            // fd.append("file", files[0]);
            debugger;
            fd.append("file", $scope.vmUploadme);
            fd.append("name", $scope.myName);
            alert($routeParams.auth);
            uploadUrl = "MyLinktoRESTBASEAPIupload1";
            $http.post(uploadUrl, fd, {
              withCredentials: true,
              headers: {
                'Content-Type': undefined,
                'Authorization': $routeParams.auth
              },
              transformRequest: angular.identity
            }).
            success(function(data, status, headers, config) {
              alert(data);
              //TODO
            }).
            error(function(data, status, headers, config) {
              alert("failure");
            });
          };
        });

<style>
            ul {
              list-style: none;
              padding: 0;
              margin: 0;
            }
            li {
              float: left;
              border: 1px solid #000;
              border-bottom-width: 0;
              margin: 3px 3px 0px 3px;
              padding: 5px 2px 5px 5px;
              background-color: #CCC;
              font: 12px tahoma, arial, verdana, sans-serif;
              color: #696969;
            }
            #mainView {
              border: 1px solid black;
              clear: both;
              padding: 0 1em;
              height: 450px;
            }
            .active {
              background-color: #FFF;
              color: #000;
            }
          </style>
&#13;
<!DOCTYPE html>
        <html>
        <head>
          <!-- JS -->
          <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
          <meta content="utf-8" http-equiv="encoding">
          <script src="script/angular/js/angular.js"></script>
          <script src="script/angular/js/angular-route.min.js"></script>
          <script src="script/angular/js/ngProgress.js"></script>
          <script src="script/custom/js/app.js"></script>
          <script src="script/custom/js/landingPage.js"></script>
          <link rel="stylesheet" type="text/css" href="style/style.css" />
        </head>
	    <body id="ng-app" ng-app="LoginApp">
          <script type="text/ng-template" id="html/login.html">
            <div ng-controller="mainController">
              <form name="userForm" ng-submit="submitForm()" novalidate>
                <div id="area" class="area">
                </div>
              </form>
            </div>
          </script>
          <div ng-view></div>
          <script type="text/ng-template" id="html/landingPage.html">
            <div id="tabs" ngController="TabsCtrl" class="area">
              <table class="stdTable" border="0">
                <tr>
                  <td>
                    <table width="100%" height="100%" align="center" border="0" cellpadding="0" cellspacing="0">
                      <cols width="95%">
                        <cols width="5%">
                          <tr>
                            <td rowspan="3" align="center">
                              <h2> Landing Page</h2>
                            </td>
                            <td align="right">
                              <a ng-click="logout();">
                                <label class="avLogin-Label">Logout</label>
                              </a>
                            </td>
                          </tr>
                          <tr>
                            <td align="right">
                              <label class="avLogin-Label">Status:Running</label>
                            </td>
                          </tr>
                          <tr>
                            <td align="right">
                              <label class="avLogin-Label">Welcome:Administrator</label>
                            </td>
                          </tr>
                    </table>
                  </td>
                </tr>
                <tr>
                  <td height="100%">
                    <ul>
                      <li ng-repeat="tab in tabs" ng-class="{active:isActiveTab(tab.url)}" ng-click="onClickTab(tab)">{{tab.title}}</li>
                    </ul>
                    <div id="mainView">
                      <div ng-include="currentTab"></div>
                    </div>
                  </td>
                </tr>
              </table>
            </div>
          </script>
          <script type="text/ng-template" id="upload.tab.html">
            <div id="viewOne">
              <h1>View One</h1>
              <input type="text" name="name" ng-model="myName" />
              <input type="file" fileread="vmUploadme" />
              <input type="button" name="button" value="Upload" ng-click='uploadFile(vmUploadme,myName)' />
            </div>
          </script>
		<script type="text/ng-template" id="bulk.tab.html">
            <div id="viewTwo">
              <h1>View Two</h1>
              <h2> Bulk User Setup </h2>
              {{message}}
            </div>
          </script>
        </body>
		</html>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

问题在于angularjs的div范围

&#13;
&#13;
$scope.upload = { fileName: '', uploadFile: '' };
$scope.uploadFile = function(){
  alert($scope.upload.uploadFile);
}
&#13;
&#13;
&#13;