{"id":20314354,"url":"https://github.com/normandy72/dynamic-html","last_synced_at":"2026-05-11T00:38:34.267Z","repository":{"id":153902767,"uuid":"587226366","full_name":"Normandy72/Dynamic-HTML","owner":"Normandy72","description":"Dynamic HTML. Coursera course \"Single Page Web Applications with AngularJS\" by Yaakov Chaikin.","archived":false,"fork":false,"pushed_at":"2023-01-10T12:30:39.000Z","size":69,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-14T12:46:39.536Z","etag":null,"topics":["angular","angularjs","html","html5","javascript","js"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Normandy72.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-10T08:57:48.000Z","updated_at":"2023-01-10T11:07:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"3c6e737f-16f9-4d70-b672-f298e4b548f2","html_url":"https://github.com/Normandy72/Dynamic-HTML","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Normandy72%2FDynamic-HTML","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Normandy72%2FDynamic-HTML/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Normandy72%2FDynamic-HTML/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Normandy72%2FDynamic-HTML/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Normandy72","download_url":"https://codeload.github.com/Normandy72/Dynamic-HTML/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241818842,"owners_count":20025208,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular","angularjs","html","html5","javascript","js"],"created_at":"2024-11-14T18:14:53.868Z","updated_at":"2026-05-11T00:38:34.231Z","avatar_url":"https://github.com/Normandy72.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"### \"Why Angular?\" in Terms of Directives\nHTML is great for declaring static documents, but it falters when we try to use it for declaring dynamic views in web applications. AngularJS lets you extend HTML vocabulary for your application. The resulting environment is extraordinarily expressive, readable and quick to develop.\n\n##### Typical Angular HTML\n```\n\u003col\u003e\n    \u003clist-item ng-repeat=\"item in list.items\"\u003e\u003c/list-item\u003e\n\u003c/ol\u003e\n```\n### Directive\nMarker on a DOM elemet that tells Angular's HTML compiler to attach a specified behavior to that DOM element.\n* The compiler can even transform / change the DOM elements and its children.\n* A marker can be attribute, element name, comment or CSS class.\n\n### Steps to Create Directive\n#### Step 1: Register Directive\n```\nangular.module('app', [])\n.controller('MyCtrl', MyCtrl)\n.directive('myTag', MyTag);\n```\n`'myTag'` - normallized name that will appear in HTML\n`MyTag` - Factory function, that returns DDO (Directive Definition Object)\n\n#### Step 2: Define Factory Function\n```\nMyTag.$inject = [...];\nfunction MyTag(...){\n    var ddo = {\n        template: 'Hello World!'\n    };\n\n    return ddo;\n}\n```\n`MyTag.$inject = [...];` - inject other sercices, controller, etc. as usual\n\n#### Step 3: Use In HTML\n`\u003cmy-tag\u003e\u003c/my-tag\u003e` - note that the name is __not__ myTag, but my-tag\n\n***\n#### _Summary_\n* Directive is a marker in HTML that Angular complies into some behavior.\n    * It can also change the HTML elements themselves.\n* Register name of directive using (normallized) camelCase.\n* Registered factory function must return a DDO.\n    * The factory function gets invoked only once.\n* With custom directives, our HTML coding becomes\n    * reusable;\n    * semantically relevant to the actual web app we're building. \n***\n\n### Restricting Directive To Element or Attribute\n```\nfunction MyDirective(){\n    var ddo = {\n        restrict: 'AE',\n        ...\n    };\n    return ddo;\n} \n```\n`restrict: 'AE'` - Default: 'A' - attribute, 'E' - element\n\n`restrict: 'A'` - Best Practice: restrict to attribute if directive is extending behavior, e.g., `ng-repeat` \n\n`restrict: 'E'` - Best Practice: restrict to element if directive is defining a component with an associated template, e.g., `\u003clist-item\u003e`\n***\n#### _Summary_\n* The DDO's restrict property determines what AngularJS compiler should look for to detect your custom directive.\n* Using directive as a different restrict type than defined will cause the compiler to simply ignore it.\n* Best Practice: use 'E' for element when directive has content along with possible behavior.\n* Best Practice: use 'A' for attribute when directive has no content and only extends the behavior of host element.\n* Class and comment directives are possible, but not used.\n***\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnormandy72%2Fdynamic-html","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnormandy72%2Fdynamic-html","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnormandy72%2Fdynamic-html/lists"}