Skip to content

Instantly share code, notes, and snippets.

@neysimoes
Created April 10, 2014 01:45
Show Gist options
  • Save neysimoes/10336250 to your computer and use it in GitHub Desktop.
Save neysimoes/10336250 to your computer and use it in GitHub Desktop.
"use strict";
var myAPP;
myAPP = angular.module("myAPP", ["ngRoute"]);
/**
* database factory
*
* @get -> get your database
* @set -> takes an index and data and set it
* @push -> insert a data in your db
* @setOk -> set a ok value to an index
* @isOk -> takes an index and check if is complete
*/
myAPP.factory("database", function() {
var database = [{
ok: true,
active: false,
page1: "result...",
page2: "result..."
},
{
ok: true,
active: false,
page1: "result...",
page2: "result..."
}];
return {
get: function() {
return database;
},
set: function(index, data) {
database[index] = data;
return database;
},
push: function(data) {
database.push(data);
return database;
},
setOk: function(index, type) {
database[index].ok = type;
return database;
},
isOk: function(index) {
if(database[index].ok === true) {
return true;
} else {
return false;
}
}
};
});
/**
* Main controller
*/
myAPP.controller("indexCtrl", ["$scope", "$location", "database", function($scope, $location, database) {
$scope.database = database.get();
$scope.next = function() {
var re = /\d+/;
var url = re.exec($location.url());
if(url === null) {
return 1;
}
return parseInt(url) +1;
};
$scope.back = function() {
var re = /\d+/;
var url = re.exec($location.url());
if(url === "1" || url === null) {
return "";
}
return parseInt(url) -1;
};
}]);
/**
* Template config.
*/
myAPP.config(function($routeProvider) {
$routeProvider
.when("/", {
templateUrl: "_templates/index.html"
})
.when("/:pageType/:pagId", {
templateUrl: function(params) {
return "_templates/" + params.pageType + "/" + params.pagId + ".html";
}
});
});
/**
* avance
*/
myAPP.directive("avance", ["$location", "database", function($location, database){
return {
restrict: "A",
scope: true,
template: '<button ng-click="click()">Click me</button> Clicked {{clicked}} times',
controller: function($scope, $element) {
$scope.click = function(){
console.log("message");
//$location.path('1/2')
console.log($location);
}
}
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment