當(dāng)前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
【学亮IT手记】AngularJS增删改查服务请求+代码剥离封装抽取示例
生活随笔
收集整理的這篇文章主要介紹了
【学亮IT手记】AngularJS增删改查服务请求+代码剥离封装抽取示例
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
//控制層
app.controller('typeTemplateController' ,function($scope,$controller,typeTemplateService,brandService){ $controller('baseController',{$scope:$scope});//繼承//讀取列表數(shù)據(jù)綁定到表單中 $scope.findAll=function(){typeTemplateService.findAll().success(function(response){$scope.list=response;} );} //分頁$scope.findPage=function(page,rows){ typeTemplateService.findPage(page,rows).success(function(response){$scope.list=response.rows; $scope.paginationConf.totalItems=response.total;//更新總記錄數(shù)} );}//查詢實體 $scope.findOne=function(id){ typeTemplateService.findOne(id).success(function(response){$scope.entity= response; }); }//保存 $scope.save=function(){ var serviceObject;//服務(wù)層對象 if($scope.entity.id!=null){//如果有IDserviceObject=typeTemplateService.update( $scope.entity ); //修改 }else{serviceObject=typeTemplateService.add( $scope.entity );//增加 } serviceObject.success(function(response){if(response.success){//重新查詢 $scope.reloadList();//重新加載}else{alert(response.message);}} ); }//批量刪除 $scope.dele=function(){ //獲取選中的復(fù)選框 typeTemplateService.dele( $scope.selectIds ).success(function(response){if(response.success){$scope.reloadList();//刷新列表$scope.selectIds=[];} } ); }$scope.searchEntity={};//定義搜索對象 //搜索$scope.search=function(page,rows){ typeTemplateService.search(page,rows,$scope.searchEntity).success(function(response){$scope.list=response.rows; $scope.paginationConf.totalItems=response.total;//更新總記錄數(shù)} );}//定義關(guān)聯(lián)品牌數(shù)據(jù)源//$scope.brandList = {data:[{id:1,text:'聯(lián)想'},{id:2,text:'中興'},{id:3,text:'華為'}]};$scope.brandList = {data:[]};//獲取關(guān)聯(lián)品牌下拉列表值$scope.findBrandList = function(){brandService.selectOptionList().success(function(response){$scope.brandList = {data:response};} );}
});
總結(jié)
以上是生活随笔為你收集整理的【学亮IT手记】AngularJS增删改查服务请求+代码剥离封装抽取示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【学亮IT手记】SpringMVC增删改
- 下一篇: 【学亮IT手记】jQuery DOM插入