controllerAs with directives and isolated scope

jmls

I want to create a ok / cancel button set where the developer can change the label

I have the following directive

angular.module('myApp')
  .directive('myButtons',function(){

    var ctrl = function ($scope) {
        var controller = this;
    };

    return {
        replace: true,
        restrict: 'E',

        scope: {
            cancelLabel: '@',
            saveLabel: '@',
            save: '&',
            cancel: '&'
        },

        templateUrl: 'directives/myButtons.html',

        controller: ctrl,
        controllerAs: 'controller',
        bindToController: true,
    };

});

the html for the directive includes the following

<div>
   <button>{{controller.cancelLabel}}</button>
   <button>{{controller.saveLabel}}</button>
</div>

the actual html calling this directive is

 <my-buttons saveLabel="Discard" cancelLabel="Cancel"></my-buttons>

however, the labels are not being set. How can I get the contents of the saveLabel= and cancelLabel= from the html

the form itself is shown, and if I manually set controller.saveLabel = "save" then it appears just fine on the save button

I know I'm missing something very simple ;)

Thanks

Pankaj Parkar

You directive element attributes are wrong, it should be hyphen(-) separated instead of using camel case.

Markup

<my-buttons save-label="Discard" cancel-label="Cancel"></my-buttons>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

mixing isolated scope and controllerAs syntax

From Dev

mixing isolated scope and controllerAs syntax

From Dev

Isolated scope for directives

From Dev

Directives with Isolated scope versions conflict

From Dev

AngularJS directives - Isolated Scope and Inherited Scope

From Dev

Multiple directives [ngController, ...] asking for new/isolated scope

From Dev

AngularJS Directives - Can Isolated Scope Attributes be required?

From Dev

Passing params to nested directives with isolated scope

From Dev

AngularJs: multiple directives asking for isolated scope on

From Dev

AngularJS directives - isolated scope special binding characters

From Dev

Angularjs isolated scope for directives without own template

From Dev

angularjs - Multiple directives asking for new / isolated scope

From Dev

AngularJS directives - isolated scope special binding characters

From Dev

AngularJS Directives - Can Isolated Scope Attributes be required?

From Dev

Communication between sibling directives inside isolated scope

From Dev

Two Directives requesting isolated scope and inherited scope on the same element

From Dev

Multiple directives [myPopup, myDraggable] asking for new/isolated scope

From Dev

Angular error in Firefox only "Multiple directives asking for isolated scope"

From Dev

Why can't multiple directives ask for an isolated scope on the same element?

From Dev

Binding functions through nested directives with isolated scope failing in Angular 1.4

From Dev

Can multiple directives for one element share an isolated scope?

From Dev

Can multiple directives for one element share an isolated scope?

From Dev

Two attribute directives with new/isolated scope on single element

From Dev

Angular Karma - Directive with isolated scope and controllerAs, calling element.isolateScope() return undefined

From Dev

Directives, Isolated scopes, Inheritance

From Dev

Directives isolated scope not working properly together with nested views? (AngularJS / UI Router)

From Dev

Angular.js how to build dynamic template parts using directives with isolated scope

From Dev

In nested Angular directives, can the child directive inherit a variable from parent's isolated scope?

From Dev

Angularjs directives isolated scope + one-way data-binding not working for objects?

Related Related

  1. 1

    mixing isolated scope and controllerAs syntax

  2. 2

    mixing isolated scope and controllerAs syntax

  3. 3

    Isolated scope for directives

  4. 4

    Directives with Isolated scope versions conflict

  5. 5

    AngularJS directives - Isolated Scope and Inherited Scope

  6. 6

    Multiple directives [ngController, ...] asking for new/isolated scope

  7. 7

    AngularJS Directives - Can Isolated Scope Attributes be required?

  8. 8

    Passing params to nested directives with isolated scope

  9. 9

    AngularJs: multiple directives asking for isolated scope on

  10. 10

    AngularJS directives - isolated scope special binding characters

  11. 11

    Angularjs isolated scope for directives without own template

  12. 12

    angularjs - Multiple directives asking for new / isolated scope

  13. 13

    AngularJS directives - isolated scope special binding characters

  14. 14

    AngularJS Directives - Can Isolated Scope Attributes be required?

  15. 15

    Communication between sibling directives inside isolated scope

  16. 16

    Two Directives requesting isolated scope and inherited scope on the same element

  17. 17

    Multiple directives [myPopup, myDraggable] asking for new/isolated scope

  18. 18

    Angular error in Firefox only "Multiple directives asking for isolated scope"

  19. 19

    Why can't multiple directives ask for an isolated scope on the same element?

  20. 20

    Binding functions through nested directives with isolated scope failing in Angular 1.4

  21. 21

    Can multiple directives for one element share an isolated scope?

  22. 22

    Can multiple directives for one element share an isolated scope?

  23. 23

    Two attribute directives with new/isolated scope on single element

  24. 24

    Angular Karma - Directive with isolated scope and controllerAs, calling element.isolateScope() return undefined

  25. 25

    Directives, Isolated scopes, Inheritance

  26. 26

    Directives isolated scope not working properly together with nested views? (AngularJS / UI Router)

  27. 27

    Angular.js how to build dynamic template parts using directives with isolated scope

  28. 28

    In nested Angular directives, can the child directive inherit a variable from parent's isolated scope?

  29. 29

    Angularjs directives isolated scope + one-way data-binding not working for objects?

HotTag

Archive