2

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.

            }


        }

    }

}];

1 Answer 1

3

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.
     }
  }
Sign up to request clarification or add additional context in comments.

10 Comments

Ok, if I give scope:false, is that possible to update in parent scope?
Yes, this is working. and i need to append a directive to DOM with ng-repeat - how to do that?
yes, works. can you help me to append a directive to DOM with ng-repeat? is it possible to do from controller or i need to use link method here?
@3gwebtrain to changes in a directive which I suggested then put that directive on ng-repeat DOM.. should work..
Actually using this directive I am showing a gallery now gallery has not element. i would like to create elements by ng-repeat, that means when the gallery div on visible the directive inside automatically works?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.