6. Extendiendo nuestro HTML con la Directiva.
Como ya vimos, nuestra vista está yendo a usar un componente nuevo para renderizar nuestras preguntas y respuestas. Este componente es una extensión del lenguaje markup y es implementado a través de una Directiva en angularJs.
'use strict'; /* jFaq Directives */ var jFaqDirectives = angular.module('jFaq.directives', []); jFaqDirectives.value('version', '0.1'); jFaqDirectives.directive('parse', ['$compile', function (compile) { return { restrict: 'E', replace: true, transclude: true, scope: { texto: '@texto', myclass: '@myclass' }, link:function (scope, element, attrs) { attrs.$observe('texto', function(value) { if (value) { var str = value.replace(/&lt;/g, '<').replace(/&gt;/g, '>'); var htmlText = '<div class="'+ attrs.myclass +'">' + str +'</div>'; var e = angular.element(htmlText); compile(e.contents())(scope); element.replaceWith(e); } }); } }; }]);
7. Recursos adicionales antes de lanzar la aplicación.
Vista auto.html.
<div class="form"> <div class="header">Datos de mi Auto:</div> <div> Marca de mi auto: <input type='text' ng-model="miAuto.marca" /><br/> Modelo de mi auto: <input type='text' ng-model="miAuto.modelo" /><br/> Matricula?: <input type='checkbox' ng-model="miAuto.tieneMatricula" disabled="true" /><br/> </div> </div> <hr/> <div class="view"> <div class="header">Mi Auto:</div> <div> Marca de mi auto: {{miAuto.marca}}<br/> Modelo de mi auto: {{miAuto.modelo}}<br/> <div ng-show="miAuto.matricula"> Matricula Creada: {{miAuto.matricula}}<br/> </div> </div> <hr/> <div> Ciudad :<input type="text" ng-model="miAuto.ciudad" /> <input type="button" value="Crear Matricula" ng-click="obtenerMatricula()" /> </div> </div>
Estilos main.css.
html, body { text-align:center; } #wrapper { margin: 0 auto; width: 800px; text-align:left; } .menu { text-align:center; background-color: green; font-weight: bold; font-size: 30px; } .menu a{ color: yellow; } .header { font-weight: bold; font-size: 18px; } .pregunta { display:block; color:red; font-weight: bold; font-size: 18px; margin-top:10px; } .respuesta { font-size: 14px; }
8. Eureka!
Espero se hayan divertido!
Comentarios recientes