0

我開發與技術的Web應用程序HTML,angularjs,JAVA,春天裏面寫的角度控制器業務邏輯/後端代碼。 我的要求是爲我的應用程序創建一個搜索頁面。請找hereangularjs應用 - 我可以在我的JavaScript文件

我需要輸入詳細信息並搜索information.Please在進入亞特蘭大從文本字段和芝加哥文本字段和SearchLocations點擊按鈕來查看信息的演示。

我所幾個問題:

1)我可以寫業務邏輯在其中被寫入的JavaScript文件作爲示例代碼我angularjs控制器如下所示:

angular.module('myApp').controller('searchController', ['$scope', function($scope) { 
    $scope.places = ['', '']; 
    $scope.searchValue = ''; 

    $scope.submit = function() { 
     $scope.showGrid = $scope.Passport; 
     if ($scope.places[0].length > 0 && $scope.places[1].length > 0) { 
     $scope.searchValue = $scope.places[0] + $scope.places[1]; 
     } 
    }; 

2)能否在我的控制器中寫入後端邏輯。如果是,你可以請建議任何鏈接,以便我可以繼續或獲得他們的知識。 我寫的JavaScript代碼,我可以說它作爲後端代碼/業務邏輯。對不起這樣的問題,但我認爲這是偉大的平臺,把我的問題,以澄清..

如果有人問我寫後端代碼爲這種搜索功能,怎麼會有人繼續。任何建議都會非常有幫助。我編寫的代碼如上面的演示程序所示。謝謝。

js代碼:

angular.module('myApp', ['ngAnimate', 'ui.bootstrap', 'ngTouch', 'ui.grid', 'ui.grid.selection', 'ui.grid.edit', 'ui.grid.cellNav']); 
    angular.module('myApp').controller('citiesCtrl', function($scope) { 
    // $scope. places = undefined; 
    $scope.items = ["Atlanta", "Chicago", "NewYork"]; 
    $scope.selectAction = function() { 
     console.log($scope.places1); 

    }; 
    }); 

    /*Controller for searchLocations button*/ 
    angular.module('myApp').controller('searchController', ['$scope', function($scope) { 
    $scope.places = ['', '']; 
    $scope.searchValue = ''; 

    $scope.submit = function() { 
     $scope.showGrid = $scope.Passport; 
     if ($scope.places[0].length > 0 && $scope.places[1].length > 0) { 
     $scope.searchValue = $scope.places[0] + $scope.places[1]; 
     } 
    }; 

    $scope.users = [{ 
     'name': 'AtlantaChicago', 
     'show': true, 
     'details': [{ 
     "Travel Date": "10/10/2014", 
     commute: "Bus" 
     }, { 
     "Travel Date": "10/11/2014", 
     commute: "flight" 
     }] 
    }, { 
     'name': 'NewYorkChicago', 
     'show': true, 
     'details': [{ 
     "Travel Date": "3/15/2016", 
     commute: "flight" 
     }, { 
     "Travel Date": "10/12/2016", 
     commute: "flight" 
     }, ] 
    }]; 
    $scope.gridOptions = { 
     enableFiltering: true, 
     columnDefs: [{ 
     name: 'Travel Date', 
     width: '5%' 
     }, { 
     name: 'Departurecommute', 
     enableFiltering: false, 
     width: '12%' 
     }], 
     rowHeight: 20, 
     enableHorizontalScrollbar: 2 

    }; 
    }]); 

HTML代碼:

<div> 
     <label> 
     Show one Grid 
     <input type="radio" name="Passport" ng-model="Passport" value=1 ng-click="ShowPassport('Y')" /> 
     </label> 
     <label>Show two Grids 
     <input type="radio" name="Passport" ng-model="Passport" value=2 ng-click="ShowPassport('N')" /> 
     </label> 
    </div> 
    <div class="row"> 
     <div class="form-group" ng-controller="citiesCtrl"> 
     <label>From</label> 
     <input type="text" ng-model="places[0]" placeholder="Type Departure City" typeahead="item for item in items | filter:$viewValue | limitTo:8"> 
     </div> 
     <div class="form-group" ng-controller="citiesCtrl"> 
     <label>To</label> 
     <input type="text" ng-model="places[1]" placeholder="Type Destination City" typeahead="item for item in items | filter:$viewValue | limitTo:8"> 
     </div> 
    </div> 

    <input type="button" value="SearchLocations" ng-click="submit()"> 

    <div ng-show="showGrid==='1'||showGrid==='2'"> 
     <div ng-repeat="user in users | filter: {name: searchValue} : true "> 
     <h3>First Grid</h3> 
     <div ui-grid="{ data: user.details }" ng-show="user.show" class="myGrid"></div> 
     </div> 
    </div> 
    <div ng-show="showGrid==='2'"> 
     <div ng-repeat="user in users | filter: {name: searchValue} : true "> 
     <h3>Second Grid</h3> 
     <div ui-grid="{ data: user.details }" ng-show="user.show" class="myGrid"></div> 
     </div> 
    </div> 

回答

0

角是MVW框架,其主要成分是視圖和模型。所以它基本上用於從服務器代碼分離頁面呈現。現在,與客戶端請求處理和頁面呈現相關的業務邏輯可能是角度控制器中的寫入,但與我們的實際數據/數據庫相關的邏輯不能寫入角度控制器。因此,您最好知道您在後臺處理中使用的代碼類型,結束並根據這個決定。

相關問題