Generic component directive
How do I make an generic component directive?
Just a generic directive for custom tags. What is a generic component directive? How do you make a generic component directive? This script and codes were developed by Yahya Kacem on 14 August 2022, Sunday.
Generic component directive - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Generic component directive</title>
</head>
<body> <!doctype html>
<html ng-app="app">
<head>
</head>
<body ng-controller="MainCtrl"> <div ng-repeat="obj in objs"> <component obj="obj"></component> </div>
<script src="http://code.angularjs.org/1.1.5/angular.min.js"></script>
</body>
</html> <script src="js/index.js"></script>
</body>
</html>
Generic component directive - Script Codes JS Codes
'use strict';
var controllers = {};
var directives = {};
directives.component = function($compile){ return { restrict: 'E', link: function (iScope, iElement, iAttrs) { if(iElement[0].getAttribute('type')){ console.log(iAttrs.type); iElement.attr(iAttrs.type, ''); iElement[0].removeAttribute('type'); $compile(iElement)(iScope); } } };
};
directives.editor = function(){ var linker = function(scope, element, attrs) {}; return { scope: { element: "=obj" }, replace: true, restrict: "EA", transclude: true, link: linker, template: '<div \ contenteditable="true"\ class="editor text-content"\ >\ {{element.content.text}}\ </div>' }
};
controllers.MainCtrl = function($scope) { $scope.objs = [ { "id": 1, "type": "editor", "content": { "text": "Some text here" } }, { "id": 2, "type": "image", "content": { "title": "title here", "alt": "alt value here", "url": "http://img.url/here.jpg" } } ];
};
var app = angular.module('app', []);
directives.component.$inject = ['$compile'];
controllers.MainCtrl.$inject = ['$scope'];
app.directive(directives);
app.controller(controllers);
Developer | Yahya Kacem |
Username | yahyaKacem |
Uploaded | August 14, 2022 |
Rating | 3 |
Size | 1,975 Kb |
Views | 22,264 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Menu hover text shadow | 1,927 Kb |
A Pen by Yahya Kacem | 2,856 Kb |
Ng2 | 1,143 Kb |
Resizable element directive design | 2,323 Kb |
Draggable directive | 2,277 Kb |
AngularJS dynamically generated list with LED status | 2,841 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
A Pen by Final Boss tommyb9 | FBtommyb9 | 55,354 Kb |
Css Rotating 3d cubes different speed | Dghez | 2,364 Kb |
Tail rose iris lined | Kbrtrm | 1,846 Kb |
Animating characters with jQuery | 042 | 2,776 Kb |
Scroll using CSS | Casperovic | 2,159 Kb |
Pomodoro Timer | Sdas13 | 2,900 Kb |
Sony Xperia Z3 Flat MockUp | Dapinitial | 4,379 Kb |
Weather App 2 | MightyJoeW | 2,877 Kb |
Responsive Minimal Blog Layout | Hackthevoid | 5,261 Kb |
Starfield using KineticJS | Asp | 3,512 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!