How to update the `$scope` object from `directive` controller

3gwebtrain

I am trying to update the $scope object from controller, But it's not updating. but in console i am getting updated status.

here is my code :

var galleryMenu = ['$route', function ($route) {

    return {

        scope : true,

        replace : true,

        template : function () {

            var page = $route.current.className || 'home';

            return galleryMenuItem(page);

        },

        controller : function ($scope, $element) {

            $scope.galleryProject = function () {

                $scope.galleryShow = !$scope.galleryShow;
                console.log($scope.galleryShow) //gives me true, but `DOM` not updating.

            }


        }

    }

}];
Pankaj Parkar

Your directive is using scope: true that means you have create a scope which is prototypically inherited from parent scope.

Then your galleryShow object should follow dot rule

$scope.model = {};
$scope.model.galleryShow = 'something';

So then in your directive you could get $scope.model object by prototypal inheritance and you could change it by $scope.model.galleryShow will change parent scope.

Directive Controller

controller : function ($scope, $element) {
     $scope.galleryProject = function () {
         $scope.model.galleryShow = !$scope.galleryShow;
         console.log($scope.model.galleryShow) //gives me true, but `DOM` not updating.
     }
  }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Update controller scope from directive

From Dev

How to pass object from controller to directive without using $scope in angularJS

From Dev

How to pass an object from a nested directive with isolated scope to parent controller scope in angular

From Dev

How do I access a directive scope from a parent directive/controller?

From Dev

Calling controller function from directive does not update scope

From Dev

Passing object from parent controller to isolated scope child directive

From Dev

how to update a value from 'controller', in a 'directive'?

From Dev

Access controller scope from directive

From Dev

change controller $scope from a directive

From Dev

How to access to the controller scope from a directive inside ng-repeat?

From Dev

How to pass a function handler from controller into directive isolated scope in AngularJs?

From Dev

How to call angular controller scope function from directive with parameters?

From Dev

How to access a scope from a directive in-another controller

From Dev

How To Call A Controller Method From Isolate Scope Directive?

From Dev

How to call angular controller scope function from directive with parameters?

From Dev

How to pass a function handler from controller into directive isolated scope in AngularJs?

From Dev

Angular how to change controller scope from onclick directive

From Dev

how can i change $scope property of controller from inside directive?

From Dev

How to Send Variable to Parent Controller from Directive without Isolate Scope

From Dev

AngularJS: directive adds object to $scope but undefined in controller

From Dev

Angular.js How to update the scope from a directive?

From Dev

Update directive variable from controller

From Dev

cannot access directive's scope object in directive's controller

From Dev

Accessing directive scope from a separate controller

From Dev

Get value from directive to $scope in controller

From Dev

Passing data from directive to parent scope controller

From Dev

Change controller scope value from directive AngularJS

From Dev

Passing variable from controller scope to directive

From Dev

Passing controller scope from directive to partial

Related Related

  1. 1

    Update controller scope from directive

  2. 2

    How to pass object from controller to directive without using $scope in angularJS

  3. 3

    How to pass an object from a nested directive with isolated scope to parent controller scope in angular

  4. 4

    How do I access a directive scope from a parent directive/controller?

  5. 5

    Calling controller function from directive does not update scope

  6. 6

    Passing object from parent controller to isolated scope child directive

  7. 7

    how to update a value from 'controller', in a 'directive'?

  8. 8

    Access controller scope from directive

  9. 9

    change controller $scope from a directive

  10. 10

    How to access to the controller scope from a directive inside ng-repeat?

  11. 11

    How to pass a function handler from controller into directive isolated scope in AngularJs?

  12. 12

    How to call angular controller scope function from directive with parameters?

  13. 13

    How to access a scope from a directive in-another controller

  14. 14

    How To Call A Controller Method From Isolate Scope Directive?

  15. 15

    How to call angular controller scope function from directive with parameters?

  16. 16

    How to pass a function handler from controller into directive isolated scope in AngularJs?

  17. 17

    Angular how to change controller scope from onclick directive

  18. 18

    how can i change $scope property of controller from inside directive?

  19. 19

    How to Send Variable to Parent Controller from Directive without Isolate Scope

  20. 20

    AngularJS: directive adds object to $scope but undefined in controller

  21. 21

    Angular.js How to update the scope from a directive?

  22. 22

    Update directive variable from controller

  23. 23

    cannot access directive's scope object in directive's controller

  24. 24

    Accessing directive scope from a separate controller

  25. 25

    Get value from directive to $scope in controller

  26. 26

    Passing data from directive to parent scope controller

  27. 27

    Change controller scope value from directive AngularJS

  28. 28

    Passing variable from controller scope to directive

  29. 29

    Passing controller scope from directive to partial

HotTag

Archive