Angular 前后端分离

1. 项目结构

Angular 前后端分离_第1张图片

 index.html




	
	Document
//顺序不要变
	

	

	

	

	

template 

 addStudent.html

	
姓名: 年龄: 性别:

showStudent.html

	
姓名 年龄 性别
{{item.name}} {{item.age}} {{item.gender}} 删除 更新

main.html

	
	

UpdateStudent.html

	
姓名: 年龄: 性别:

 app.js

//千万不要忘了注册Controller
var m = angular.module('myApp',['ui.router','StudentController']);
m.config(function($stateProvider,$urlRouterProvider){

	 $urlRouterProvider.otherwise("/Main/queryStudent");

	$stateProvider.state("Main",{

		url:'/Main',

		views:{

			"content":{

				templateUrl:"templates/main.html"

			}

		}

	}).state("Main.queryStudent",{

		url:'/queryStudent',

		views:{

			"Main_content@Main":{

				controller:'ShowStudentCNTR',

				templateUrl:"templates/showStudent.html"

			}

		}

	}).state("Main.addStudent",{

		url:'addStudent',

		views:{

			"Main_content@Main":{

				controller:'AddStudentCNTR',

				templateUrl:"templates/addStudent.html"

			}

		}

	}).state("Main.getStudent",{

		url:'/getStudent/{id}',

		views:{

			"Main_content@Main":{

				controller:'GetStudentCNTR',

				templateUrl:'templates/UpdateStudent.html'

			}

		}
	});


});






 StudentController.js

//牛逼的双向数据绑定
var m = angular.module("StudentController",[]);

m.controller("GetStudentCNTR",function($scope,$stateParams){

	var id = $stateParams.id;

	alert(id);
});

m.controller("AddStudentCNTR",function($scope){

	$scope.formData={

		gender:0

	}

     $scope.add = function(){

     		alert($scope.formData.name)
     		alert($scope.formData.age);
     		alert($scope.formData.gender);

     }

});

m.controller("ShowStudentCNTR",function($scope){

	$scope.datas = [{id:1,name:'哈哈哈',age:18,gender:'男'},{id:2,name:'哈哈2',age:18,gender:'男'},{id:3,name:'哈哈3',age:18,gender:'男'},{id:4,name:'哈哈哈',age:18,gender:'男'},{id:1,name:'哈哈哈',age:18,gender:'男'},{id:1,name:'哈哈哈',age:18,gender:'男'},{id:1,name:'哈哈哈',age:18,gender:'男'},{id:1,name:'哈哈哈',age:18,gender:'男'}];

	var pos = 0;

     $scope.delete = function(id){

     	for(var i=0;i<$scope.datas.length;i++){


     			var ob = $scope.datas[i];

     			if(ob.id==id){

     				pos = i;

     				break;

     			}


     	}

     	$scope.datas.splice(pos, 1);

        $state.go("Main");


     }


});

 

 

 源码点此下载 密码:enht

 

 

 

 

你可能感兴趣的:(angular)