bind $scope in Directives/Controller

Gabriel Lopes

After binded a scope to my Directive/Controller I can't use its own directive anymore, is there something I should fix? I've tried to find an answer but nothing so far..

ANGULARJS:

return {
        scope: { fullpost:'@' },
        controller: function ($scope, $element) {

            // Edit Btn
            $scope.editbtn = "Edit";

the $scope.editbtn doesn't display in the html anymore.

HTML:

<full-post fullpost="fullpost">
<!-- edit tools -->
<div class='yardtools'>
<button id='edit' ng-click='edit()'><i class='fa fa-pencil-square-o'></i> {{ editbtn }}</button>
<button id='update' class='hidden'><i class='fa fa-wrench'></i> Update</button>
<button id='delete'ng-click='delete()'class='hidden'><i class='fa fa-trash-o'></i> Delete</button>
    </div>
<!-- post -->
<div class='yardman-post' data-post-id=" + id + ">
    <div ym='info'>
        <p>Post id: <em> {{ fullpost.id }}</em>, Posted on: <em>{{ fullpost.date }}</em>, by <em>AUTHOR</em>
        </p>
    </div>
    <div ym='title' contenteditable='false'>{{ fullpost.title }}</div>
    <div ym='body' contenteditable='false'>{{ fullpost.text }}</div>
</div>
</full-post>
Pankaj Parkar

I'd suggest you to put your inner html of to directive element to move it to some template, though there is option to use ng-transclude but at looking at your current html you could use you inner content of directive using template & access that template using templateUrl.

directiveTemplate.html

<div class='yardtools'>
<button id='edit' ng-click='edit()'><i class='fa fa-pencil-square-o'></i> {{ editbtn }}</button>
<button id='update' class='hidden'><i class='fa fa-wrench'></i> Update</button>
<button id='delete'ng-click='delete()'class='hidden'><i class='fa fa-trash-o'></i> Delete</button>
    </div>
<!-- post -->
<div class='yardman-post' data-post-id=" + id + ">
    <div ym='info'>
        <p>Post id: <em> {{ fullpost.id }}</em>, Posted on: <em>{{ fullpost.date }}</em>, by <em>AUTHOR</em>
        </p>
    </div>
    <div ym='title' contenteditable='false'>{{ fullpost.title }}</div>
    <div ym='body' contenteditable='false'>{{ fullpost.text }}</div>
</div>

Directive

return {
    scope: { fullpost:'@' },
    templateUrl: 'directiveTemplate.html'
    controller: function ($scope, $element) {

        // Edit Btn
        $scope.editbtn = "Edit";
     }
 }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Bind element to scope variable

From Dev

bind $scope in Directives/Controller

From Dev

Javascript scope basics : .bind or self =this?

From Dev

Does .bind break $scope in angularjs?

From Dev

Bind to attributes in prototypically inherited scope

From Dev

Bind ngOptions to array outside of scope

From Dev

Angular bind controller to new scope

From Dev

Bind a controller $scope to objects in service

From Dev

Bind to attributes in prototypically inherited scope

From Dev

Angular bind directive scope dynamically

From Dev

angularjs bind to controller with isolated scope

From Dev

Can't bind $scope in controller when scope: {} is defined in the directive

From Dev

AngularJS: How to bind a $scope variable to another $scope.variable

From Dev

How to bind content of tag into into directive's scope?

From Dev

JavaScript setInterval scope issue: an alternative to bind

From Dev

Bind scope to function outside of function call

From Dev

bind callback to directive without isolated scope

From Dev

Bind ngModel to AngularJS directive with isolated scope

From Dev

Is it ok to bind whole service to controller scope?

From Dev

Angularjs won't bind scope variable with function?

From Dev

Scope changes in directive's bind function are not reflected

From Dev

Bind element to existing AngularJS scope in a different frame

From Dev

Angular directive: bind to variable in parent scope

From Dev

AngularJS Bind service array variable to controller scope

From Dev

Angular bind service property to a controller scope

From Dev

AngularJS : Bind to transclusive directive without isolating the scope

From Dev

AngularJS: Bind angular service property to scope

From Dev

data-ng-bind from $scope controller

From Dev

can't bind scope variables in angularjs

Related Related

  1. 1

    Bind element to scope variable

  2. 2

    bind $scope in Directives/Controller

  3. 3

    Javascript scope basics : .bind or self =this?

  4. 4

    Does .bind break $scope in angularjs?

  5. 5

    Bind to attributes in prototypically inherited scope

  6. 6

    Bind ngOptions to array outside of scope

  7. 7

    Angular bind controller to new scope

  8. 8

    Bind a controller $scope to objects in service

  9. 9

    Bind to attributes in prototypically inherited scope

  10. 10

    Angular bind directive scope dynamically

  11. 11

    angularjs bind to controller with isolated scope

  12. 12

    Can't bind $scope in controller when scope: {} is defined in the directive

  13. 13

    AngularJS: How to bind a $scope variable to another $scope.variable

  14. 14

    How to bind content of tag into into directive's scope?

  15. 15

    JavaScript setInterval scope issue: an alternative to bind

  16. 16

    Bind scope to function outside of function call

  17. 17

    bind callback to directive without isolated scope

  18. 18

    Bind ngModel to AngularJS directive with isolated scope

  19. 19

    Is it ok to bind whole service to controller scope?

  20. 20

    Angularjs won't bind scope variable with function?

  21. 21

    Scope changes in directive's bind function are not reflected

  22. 22

    Bind element to existing AngularJS scope in a different frame

  23. 23

    Angular directive: bind to variable in parent scope

  24. 24

    AngularJS Bind service array variable to controller scope

  25. 25

    Angular bind service property to a controller scope

  26. 26

    AngularJS : Bind to transclusive directive without isolating the scope

  27. 27

    AngularJS: Bind angular service property to scope

  28. 28

    data-ng-bind from $scope controller

  29. 29

    can't bind scope variables in angularjs

HotTag

Archive