JavaScript Creating directive to part of template which is shown after a click

I've got a template with two kind of article-container: Viewer and Editor:

<article ng-if="!editor" ng-controller="article">
    <div>Some content</div>
</article>

<article ng-if="editor" ng-controller="article">
    <div mySharedScope></div>
</article>

While clicking the button the user can switch between those two container:

<button ng-click="editor = !editor" ng-bind="editor ? 'Abort' : 'Edit'"></button>

Now I want to create a directive on the second container. So this is what I did:

app.directive('mySharedScope', function () {
    return {
        template: 'New content'
    };
});

But something is missing, as this doesn't work. I want to use a directive to do some DOM mainpulation link: function ($scope, element, attrs) { }

Answer:1

Two things, first is that the directive mySharedScope will transform in it's directive definition from camel case

<div mySharedScope></div>

to a dashes like so

<div my-shared-scope></div>

After you switch that out, you'll need to make sure you're translcuding content nested inside of your first directive (article), and placing the ng-transclude directive inside of its template.

see docs for this on angular website

as a basic implementation of this, i've created a fiddle with the two of your two directives that appropriately switch when a button is triggered. The content is transcluded here, so feel free to cherry pick what you need from it.

https://jsfiddle.net/wvty8rpc/2/

Answer:2

JS FIDDLE I have a function as follows in javascript function myfun() { var a = "'\u0c39"; alert(a); } When i called this function i am able to see correct letter(This letter is telugu ...

JS FIDDLE I have a function as follows in javascript function myfun() { var a = "'\u0c39"; alert(a); } When i called this function i am able to see correct letter(This letter is telugu ...

  1. unable to convert unicode to string

[updated] given object: var node = { 'comments': 'http://example.com/post/#comments', 'slash:comments': '143', } One can access the 'title' parameter using indexed access or dot notation: node["...

[updated] given object: var node = { 'comments': 'http://example.com/post/#comments', 'slash:comments': '143', } One can access the 'title' parameter using indexed access or dot notation: node["...

Ok guys. I've built a web application with some friends that is somehow complex and took us some time to built. It is entirely built using JavaScript Now the application has some functions which we ...

Ok guys. I've built a web application with some friends that is somehow complex and took us some time to built. It is entirely built using JavaScript Now the application has some functions which we ...

  1. server side javascript frameworks
  2. server side javascript marketing cloud
  3. server side javascript example
  4. server side javascript injection
  5. server side javascript tutorial
  6. server side javascript vs client side
  7. server side javascript console.log
  8. server side javascript w3schools
  9. server side javascript object
  10. server side javascript injection payloads
  11. server side javascript code injection
  12. server side javascript vs php
  13. server side javascript libraries
  14. server side javascript code
  15. server side javascript object example
  16. server side javascript is also known as
  17. server side javascript is known as
  18. server side javascript object mcq
  19. server side javascript has stopped working
  20. server side javascript injection example

Following this example: Protractor get element by model in repeater array, I am running into a head scratcher. I want to send input value to an element inside of a repeater. Hopefully it is a simple ...

Following this example: Protractor get element by model in repeater array, I am running into a head scratcher. I want to send input value to an element inside of a repeater. Hopefully it is a simple ...

  1. sendkeys element not interactable
  2. send_keys element not visible
  3. sendkeys to element
  4. send keys without element selenium
  5. selenium sendkeys element not interactable
  6. sendkeys to element python
  7. selenium sendkeys to element
  8. sendkeys to element selenium
  9. javascript sendkeys to element
  10. webdriver sendkeys to element
  11. sendkeys to active element
  12. send_keys cannot focus element
  13. selenium send keys without element c#
  14. selenium send keys without element java
  15. selenium send keys without element python
  16. appium send keys without element
  17. actionchains.sendkeys to element
  18. js sendkeys to element
  19. protractor send keys without element
  20. element.sendkeys(file) python