I have the following code:
1.- Why use directives ?, in this case it would not be enough to use controller?
2.- Does the controller always have a function with scope?
(function() {
var modulo=angular.module('tnt.ui.components', []);
modulo.directive('userInfo', [function() {
return {
restrict: 'E',
template:'Nombre: {{user.name}}, email: <a href="mailto:{{user.email}}">{{user.email}}</a>'
};
}]);
modulo.controller('DemoDirectivesCtrl', function($scope){
$scope.user = {
name: 'Jose',
email: '[email protected]'
};
});
}());
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script>
<script src="script.js"></script>
</head>
<body>
<div ng-app="tnt.ui.components" ng-controller="DemoDirectivesCtrl">
<user-info />
</div>
</body>
</html>