是的,已经用过Angular了 ,艺多不压身嘛
简介:
前端JS框架,MVC 模块化 自动化双向数据绑定 依赖注入
知识点:
1、双向绑定:<input ng-model="myname"> {{myname}}
小Demo
<script>中建立模块
Var app=angular.module("myApp",[]);
创建控制器 $scope控制与视图层交换数据的桥梁
App.controller("myController",function($scope){
$scope.add=function(){
//Return parseInt($scope.x)+parseInt($scope.y);
$scope.z=parseInt($scope.x)+parseInt($scope.y);
}
$scope.list=[306,200,404,500];
$scope.list=[
{name:"ni",math:100,english:100},
{name:"ni2",math:100,english:100},
{name:"ni2",math:100,english:100},
];
});
</script>
<script>
<var app=angular.module("myApp",[]);
App.controller("myController",function($scope,$http){
$scope.findList=function(){
$http.get("data.json").success(
Function(response){
$scope.list=response;
}
);
//$scope.findList();引用此处逻辑就走这个方法
});
</script>
<body>中引入
<body ng-app="myApp" ng-controller="myController" ng-init="findList()">
<input ng-model="x" >
<input ng-model="y">
//{{add()}}
<button ng-click="add()"/>{{z}}
<table>
<tr ng-repeat="x in list"><td>{{x}}</td>
</table>
<table>
<tr><td>姓名</td><td>数学</td><td>英语</td></tr>
<tr ng-repeat="entity in list">
<td>{{entity.name}}</td>
<td>{{entity.math}}</td>
<td>{{entity.englisth}}</td>
<tr/>
</table>
</body>
var app=angular.module('pinyougou', []);//定义模块
app.controller('brandController' ,function($scope,$http){
//读取列表数据绑定到表单中
$scope.findAll=function(){
$http.get('../brand/findAll.do').success(
function(response){
$scope.list=response;
}
);
}
});
<body class="hold-transition skin-red sidebar-mini"
ng-app="pinyougou" ng-controller="brandController">
分页:
var app=angular.module('pinyougou',['pagination']);//定义品优购模块
页面:
<tm-pagination conf="paginationConf"></tm-pagination>
插入:
//保存
$scope.save=function(){
$http.post('../brand/add.do',$scope.entity ).success(
function(response){
if(response.success){
//重新查询
$scope.reloadList();//重新加载
}else{
alert(response.message);
}
}
);
}
界面:
<tr>
<td><input class="form-control" ng-model="entity.name" placeholder="品牌名称" ></td>
</tr>
<tr><td>首字母</td>
<td><input class="form-control" ng-model="entity.firstChar" placeholder="首字母"> </td>
</tr>
//新建按钮,对entity变量进行清空操作
ng-click="entity={}"
删除:
复选框:
<input type="checkbox" ng-click="updateSelection($event,entity.id)">
$scope.selectIds=[];//选中的ID集合
//更新复选
$scope.updateSelection = function($event, id) {
if($event.target.checked){//如果是被选中,则增加到数组
$scope.selectIds.push( id);
}else{
var idx = $scope.selectIds.indexOf(id);
$scope.selectIds.splice(idx, 1);//删除
}
}
//批量删除
$scope.dele=function(){
//获取选中的复选框
$http.get('../brand/delete.do?ids='+$scope.selectIds).success(
function(response){
if(response.success){
$scope.reloadList();//刷新列表
}
}
);
}