The parental context is not bound to the isolated scope of the custom directive

Below is the custom directive implemented:

(function() {
    angular.module('commentsDirective', [])

    .directive('mngComments', mngComments)

    function mngComments() {
        return {
            restrict: 'AE',
            scope: { },
            templateUrl: '/comments/comments.html',
            controller: 'CommentsController',
            controllerAs: 'vm',
            bindToController: {   
                moment: '=',
                comments: '=',
                showComments: '='
            }
        };
    };
})();

Usage of the directive and passing values:

<div mng-comments moment="vm.moments[0]" comments="vm.comments" showComments="true"></div>

There is a hard-coded "true" in showComments. However, in the comments.html file:

comments {{vm.showComments}}

The displayed value is {{vm.showComments}} without any assigned value. It simply shows 'comments'. vm.moments and vm.comments are being correctly passed.

Answer №1

(function() {
    angular.module('notesDirective', [])
    
    .directive('mngNotes', mngNotes)
    
    function mngNotes() {
        return {
            restrict: 'AE',
            scope: { },
            template: '<div>example {{vm.displayNotes}}</div>',
            controller: function(){},
            controllerAs: 'vm',
            bindToController: {   
                point: '=',
                notes: '=',
                displayNotes: '='
            }
        };
    };
})();
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.7/angular.js"></script>

<div ng-app="notesDirective">
  <div mng-notes
       point="vm.points[0]"
       notes="vm.notes"
       display-notes="true">
  </div>
</div>

Just remember to use hyphen case in the HTML for bindings/scope properties that are in the JavaScript. HTML is not case sensitive, so use the hyphen instead of camel casing.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When leaving the page, onBeforeUnload function aborts any ongoing HTTP requests

When attempting to send an http request using the fetch API upon leaving the page, I am encountering a blockage of the request. Is there a solution to this issue without resorting to using an async function or waiting for the request to complete, which tri ...

When you click on the Admin Panel Side menu, the page refreshes instead of expanding the menu item

I have encountered a strange problem with the AdminLTE admin panel template that I am using in my Angular 11 application. Everything is loading fine with the menu items, but when I click on an item, instead of expanding the group, the page refreshes. Here ...

Unable to trigger onActivated in Quasar (Vue 3) component

I can't seem to get the onActivated function in Vue 3 to trigger, even though I've implemented it before successfully. It's puzzling me as nothing seems to be happening. Currently, I'm using Vue version 3.0.0. Here is a snippet of my co ...

What are the restrictions of using the Angular orderby array function?

Is there a restriction on the number of values in an Angular orderby predicate? I am having trouble getting anything with more than 2 fields to function properly. It seems that anything after the 2nd index does not work. However, if I rearrange the fields ...

JavaScript tag filtering system: Display only the div elements that contain all the specified classes in an array; otherwise, hide them

Can you provide some guidance on accomplishing this task? I am looking to toggle the visibility of a div based on its classes and an array. If the array contains the term something, then only divs with the class something will be displayed. If the array ...

Unexpected behavior: Angular4/Javascript Date object alters when timezone is specified in Date constructor

In my Angular 4 application, I encountered an issue with a date retrieved from an API call. The date is in the format '1990-03-31T23:00:00-06:00' and when attempting to create a Date object and retrieve the month using getMonth(), it returns the ...

Encountering a WriteableDraft error in Redux when using Type Definitions in TypeScript

I'm facing a type Error that's confusing me This is the state type: export type Foo = { animals: { dogs?: Dogs[], cats?: Cats[], fishs?: Fishs[] }, animalQueue: (Dogs | Cats | Fishs)[] } Now, in a reducer I&a ...

Troubles arising from React component integration with Gatsby JS

As I dive into creating a stunning portfolio website with Gatsby js, I encountered an issue while trying to integrate the card component from the gatsby-plugin-material-ui package. The card resides in a separate file within my components directory and is e ...

Why is it displaying undefined even though there is data stored in Firebase?

I am experiencing an issue where the datatable row is displaying "undefined" instead of the data from my Firebase database. Even when I tried inserting random data into the HTML file for the datatable, it still shows undefined. Here is a link to My Datata ...

Unable to sort array within a computed property in Vue.JS

Currently, I am working on enhancing my skills in Vue.js and have encountered an issue with sorting arrays in Vue.js. Despite using the sort(a-b) method for ascending order (least alphabet/value first), the array remains unchanged. Even with a function ins ...

The Middleware does not catch Promise rejections that occur with await

I'm currently utilizing Nodejs in my project. One issue I am facing is with a promise that is requested after a delay. It seems like my Middleware is unable to catch the error, however, uncaughtException is able to handle it. router.all('/incas ...

Using an onclick function to increment and decrement values

Can anyone help me figure out how to reverse a function onclick? Here is the function: var theTotal = 0; $('button').click(function(){ theTotal = Number(theTotal) + Number($(this).val()); $('.total').text(theTotal); }); ...

Adjust the CSS property of a div to have a fixed position when scrolling

I attempted to implement a fixed div on scroll in Vue.js using the following code: ... async created() { window.addEventListener('scroll', this.calendarScroll); } methods: { calendarScroll() { console.log('Scroll'); cons ...

The required validator in Mongoose is not being triggered by the function

I'm trying to use a function as a validator in a mongoose schema, but it doesn't seem to work if I leave the field empty. The documentation states: Validators are not run on undefined values. The only exception is the required validator. You ...

Exploring jQuery: Choosing all li elements starting from a specific index to the end

Is there a way to select the last item, li:eq('+(lastItemIndex)+')', and all subsequent items until the end? Check out this JSFiddle demo for an example of changing elements in li from 3 onwards. ...

Does SameSite=Lax grant permission for GET requests from third-party sources?

After exploring the MDN documentation on SameSite=Lax, I have come to understand the following: In modern browsers, cookies can be sent along with GET requests initiated by a third-party website or during top-level navigations. This is the default behav ...

How can you leverage Symfony to iterate through a JSON array efficiently?

After selecting a user, I am attempting to display a list of contracts. To achieve this, I have written the following query: /** * @param $firstname * @param $lastname * @return mixed * @throws DBALException */ public function getListPerUser($firs ...

The Angular application is experiencing issues following an update from version 11 to version 12

I recently updated my Angular project following these steps: npm cache clean --force npm uninstall @angular/cli@latest @angular/core@latest npm install -g @angular/cli@latest @angular/core@latest After completing the above steps, I proceeded to delete th ...

How can I showcase data retrieved from a function using Ajax Datatable?

I have implemented an Ajax function that retrieves data from a PHP file and displays it in a DataTable. Initially, this setup was working fine. However, when I added a new function to the PHP file, my Ajax function stopped retrieving data from the file. I ...

Using jQuery to select the next table cell vertically

Is there a way to utilize jQuery to access the cell (td) directly below a given cell in a traditional grid-layout HTML table (where each cell spans only one row and column)? I understand that the code below will assign nextCell to the cell immediately to ...