Erick Wendel
Microsoft MVP, Speaker and Community Manager
(function (angular){
var app = angular.module('presentation', []);
app.factory('Introduction', function () {
return { message: 'Hello Guys :D'};
});
})(angular);
angular.module('app',
['app.controllers',
'app.directives',
'app.services' ]);
angular.module('app.controllers', ['usuario.controller']);
angular.module('app.services', ['usuario.services']);
angular.module('app.directives', ['usuario.directives']);
<span class="done-{{user.isWoman}}">{{user.name}}</span>
<label>Soma 2+2 = </label>
<output>{{2 + 2}}</output>
angular.module('app')
.controller('TestCtrl', [function () {
this.usuario = 'Erick Wendel';
}]);
<!DOCTYPE html>
<html ng-app="app">
<head>
<title>Hello App</title>
<script src="bower_components/angular/angular.min.js"></script>
</head>
<body>
<div ng-controller="TesteCtrl as vm">
{{vm.usuario}}
</div>
</body>
</html>
<div>
<div ng-repeat="usuario in vm.usuarios">
<span> {{usuario.nome}}</span>
<span> {{usuario.telefone}}</span> |
<span> {{usuario.sexo}}</span> |
</div>
</div>
<div>
<div ng-repeat="usuario in vm.usuarios">
<div ng-show="{{usuario.sexo === 'Feminino'}}">
<span> {{usuario.nome}}</span>
<span> {{usuario.telefone}}</span> |
<span> {{usuario.sexo}}</span>
</div>
</div>
</div>
angular.module('app')
.directive('meusUsuarios', function () {
return {
restrict: 'E',
template:
'<div>' +
'<div ng-repeat="usuario in vm.usuarios">' +
'<span> {{usuario.nome}}</span> ' +
'<span> {{usuario.telefone}}</span> |' +
'<span> {{usuario.sexo}}</span>' +
'</div>' +
'</div>'
};
});
<meus-usuarios></meus-usuarios>
{{usuario.nome | uppercase}} //saida com a string MAIUSCULA
{{usuario.sexo | lowercase}} //saida com string minuscula
angular.module('app')
.filter('homemMulher', function (){
function filtrarHomemMulher(input) {
return input === "Feminino" ? "Mulher" : "Homem";
}
return filtrarHomemMulher;
});
<div ng-repeat="usuario in vm.usuarios">
<span> {{usuario.nome | uppercase}}</span>
<span> {{usuario.telefone }}</span> |
<span> {{usuario.sexo | homemMulher}}</span>
</div>
angular.module('app')
.config(function ($routeProvider) {
$routeProvider
.when("/teste", {
templateUrl: "teste.html",
controller: "TestCtrl",
controllerAs: 'vm'
});
$routeProvider.otherwise({ redirectTo: '/teste' });
});
<!DOCTYPE html>
<html>
<head>
<title>Hello</title>
<script src="../bower_components/angular/angular.min.js"></script>
<script src="../bower_components/angular-route/angular-route.min.js"></script>
<script src="app.js"></script>
</head>
<body ng-app="app" >
<div ng-view></div>
</body>
</html>
angular.module('app')
.config(['$routeProvider', function ($routeProvider) {
$routeProvider
.when("/teste", {
templateUrl: "teste.html",
controller: "TestCtrl",
controllerAs: 'vm'
});
$routeProvider.otherwise({ redirectTo: '/teste' });
}]);
<!doctype html>
<html ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js"></script>
</head>
<body>
<div>
<label>Name:</label>
<input type="text" ng-model="yourName" placeholder="Enter a name here">
<hr>
<h1>Hello {{yourName}}!</h1>
</div>
</body>
</html>
By Erick Wendel