Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // create the module and name it scotchApp
- var scotchApp = angular.module('scotchApp', ['ngRoute']);
- // configure our routes
- scotchApp.config(function($routeProvider) {
- $routeProvider
- // route for the home page
- .when('/', {
- templateUrl : 'pages/home.html',
- controller : 'mainController'
- })
- // route for the book page
- .when('/books', {
- templateUrl : 'pages/book.html',
- controller : 'booksController'
- })
- // route for the client page
- .when('/books/:id', {
- templateUrl : 'pages/book.html',
- controller : 'booksController'
- })
- .otherwise({ redirectTo : "/"});
- });
- // create the controller and inject Angular's $scope
- scotchApp.controller('mainController', function($scope) {
- // create a message to display in our view
- $scope.message = 'Everyone come and see how good I look!';
- });
- scotchApp.controller('booksController', function($scope,$http,$routeParams) {
- $http.get('script/list.php').then (function(response){$scope.datos = response.data.tasks;});
- // Add new task
- $scope.addTask = function () {
- var add = confirm('desear adicionar datos ?');
- if (add==true) {
- $http.post('script/create.php', {
- dato: $scope.dato
- })
- .then(function success(e) {
- $scope.errors = [];
- $scope.datos.push(e.data.dato);
- }, function error(e) {
- $scope.errors = e.data.errors;
- });
- $scope.dato = {};
- $scope.edit = false;
- }
- };
- $scope.editData = function(index){
- var edt = confirm('desea editar dato');
- if (edt==true) {
- $scope.dato = $scope.datos[index];
- $scope.edit = true;
- }
- };
- // update the task
- $scope.updateTask = function () {
- var upd= confirm("estas seguro editar");
- if (upd==true) {
- $http.post('script/update.php', {
- dato: $scope.dato
- })
- .then(function success(e) {
- $scope.errors = [];
- }, function error(e) {
- $scope.errors = e.data.errors;
- });
- $scope.dato = {};
- $scope.edit = false;
- };
- }
- // delete the task
- $scope.deletData = function (index) {
- var conf = confirm("Estas seguro querer eliminar estos datos" + index );
- if (conf == true) {
- $http.post('script/delete.php', {
- dato: $scope.datos[index]
- })
- .then(function success(e) {
- $scope.errors = [];
- $scope.datos.splice(index, 1);
- }, function error(e) {
- $scope.errors = e.data.errors;
- });
- }
- };
- $scope.deleteData = function( nom ) {
- //alert (nom);
- if ( confirm("Seguro?") ) {
- $http.get('script/delete.php?dato='+ nom ).success(function(data){
- if( data.err !== undefined ){
- window.location = "#/books";
- return;
- }
- $scope.alumno = data;
- });
- }
- }
- });
- scotchApp.controller('bookController', function($scope, $routeParams, $http) {
- var id = $routeParams.id;
- $scope.myCallback = function (valueFromDirective) {
- console.log(valueFromDirective);
- };
- $scope.alumno = {};
- });
Add Comment
Please, Sign In to add comment