Skip to content

Instantly share code, notes, and snippets.

@cortezcristian
Last active November 23, 2017 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cortezcristian/bdc04872d81e0de491873c579b2ceed0 to your computer and use it in GitHub Desktop.
Save cortezcristian/bdc04872d81e0de491873c579b2ceed0 to your computer and use it in GitHub Desktop.

Repo https://github.com/cortezcristian/angular-softing

Cheatsheet Directives https://egghead.io/articles/angularjs-core-services-directive-definition-object-and-ui-router-cheat-sheets

Bootsnip

https://bootsnipp.com/snippets/kW9gA

Code

<!doctype html>
<html ng-app="app1">
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script>
  </head>
  <body>
    <div ng-controller="CalcCtrl" class="calculator">
      <div class="top">
        <span class="clear">C</span>
        <input class="screen" />
      </div>
      <button ng-repeat="n in pad">{{n | uppercase}}</button>
    </div>
    <script>
      angular.module('app1', []).controller('CalcCtrl', function($scope){
        debugger;
        $scope.pad = '12345+-=cX';

      });
    </script>
  </body>
</html>

<!doctype html>
<html ng-app="app1">
<head>
<link rel="stylesheet" href="estilos.css" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script>
</head>
<body>
<!-- V -->
<div class="row softing">Change me! :D</div>
<softing></softing>
<input type="text" ng-model="valorBuscado" />
<ol>
<li ng-repeat="name in ['JOse', 'Nacho', 'Kevin'] | filter:valorBuscado">{{name}}</li>
</ol>
<div ng-controller="CalcCtrl" class="calculator">
<div class="top">
<span class="clear" ng-click="clear()">C</span>
<input type="text" class="screen" ng-model="screen" />
</div>
<div class="keys">
<div ng-repeat="row in pad">
<button
class="estilo-{{n}}"
ng-class="{ 'operator': $index === 3 }"
ng-repeat="n in row"
ng-click="keyCalc(n)">
{{n | uppercase}}
</button>
</div>
</div>
</div>
<softing></softing>
<script>
angular.module('app1', [])
.controller('CalcCtrl', function($scope, $filter){
$scope.screen = '';
//$scope.pad = '12345+-=cX';
$scope.pad = ['789+', '456-', '123/', '0.=*'];
$scope.texto = "sdklajlkiuouaouaoauasdnfnj";
$scope.textoSinV = $filter('sinvocales')($scope.texto);
$scope.clear = function(){
$scope.screen = '';
}
$scope.keyCalc = function(n){
console.log(n);
switch (n) {
case '=':
$scope.screen = eval($scope.screen);
break;
default:
$scope.screen += n;
break;
}
}
})
.directive('softing', function(){
return {
restrict: 'CEAM',
template: '<h1>Hola mundo! {{time | date:"HH:mm:ss"}}</h1>',
link: function(scope, el, attrs) {
console.log(scope, el, attrs);
scope.time = Date.now();
debugger;
},
};
})
.filter('sinvocales', function(){
return function(valor) {
return valor.replace(/[aeiou]/g, '');
}
});
</script>
</body>
</html>
<!doctype html>
<html ng-app="app1">
<head>
<link rel="stylesheet" href="estilos.css" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script>
</head>
<body>
<div class="row softing">Change me! :D</div>
<div>
<calculator></calculator>
<calculator></calculator>
</div>
<script>
angular.module('app1', [])
.controller('CalcCtrl', function(softingServ, $scope, $filter){
$scope.montoIva = softingServ.calcularIva(100);
$scope.screen = '777';
//$scope.pad = '12345+-=cX';
$scope.pad = ['789+', '456-', '123/', '0.=*'];
$scope.texto = "sdklajlkiuouaouaoauasdnfnj";
$scope.textoSinV = $filter('sinvocales')($scope.texto);
$scope.clear = function(){
$scope.screen = '';
}
$scope.keyCalc = function(n){
console.log(n);
switch (n) {
case '=':
$scope.screen = eval($scope.screen);
break;
default:
$scope.screen += n;
break;
}
}
})
.factory('LocalStorageServ', function() {
return {
get: function(key) {
var val = window.localStorage.getItem(key);
return JSON.parse(val);
},
set: function(key, val) {
window.localStorage.setItem(key, JSON.stringify(val));
},
delete: function(key) {
window.localStorage.removeItem(key);
},
clear: function(key) {
window.localStorage.clear();
},
};
})
.factory('calcServ', function(softingServ) {
return {
derivada: function() {
}
};
})
.directive('calculator', function(LocalStorageServ){
return {
restrict: 'E',
scope: '=',
templateUrl: './calc.html',
link: function($scope, el, attrs) {
var val = LocalStorageServ.get('calc');
$scope.screen = val || '';
//$scope.pad = '12345+-=cX';
$scope.pad = ['789+', '456-', '123/', '0.=*'];
$scope.clear = function(){
$scope.screen = '';
}
$scope.$watch('screen', function() {
console.log('screen cambio:', $scope.screen);
LocalStorageServ.set('calc', $scope.screen);
});
$scope.keyCalc = function(n){
console.log(n);
switch (n) {
case '=':
$scope.screen = eval($scope.screen);
break;
default:
$scope.screen += n;
break;
}
}
},
};
})
.directive('softing', function(){
return {
restrict: 'CEAM',
template: '<h1>Hola mundo! {{time | date:"HH:mm:ss"}}</h1>',
// controller: 'CalcCtrl',
link: function(scope, el, attrs) {
console.log(scope, el, attrs);
scope.time = Date.now();
debugger;
},
};
})
.filter('sinvocales', function(){
return function(valor) {
return valor.replace(/[aeiou]/g, '');
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment