0

I have this directive agreementDialog that in turn uses the generic dialog directive myapp-dialog-window-modal:

angular.module('myapp.common.extra').directive('agreementDialog', function () {

    return {
        restrict: 'E',
        replace: true,
        template: '<div><myapp-dialog-window-modal window-title="Agreements" dialog-visible="agreementDialogVisible">'
                    + '<p>You need to accept the new terms.</p>'
                    + '<p><label><input type="checkbox" ng-model="variableInTranscludedChildScope"/>I accept the agreement</label></p>'
                    + '<p><button ng-click="submitAgreement(didAgree)">Submit</button></p>'
                + '</myapp-dialog-window-modal></div>',

        controller: function ($scope) {

            $scope.submitAgreement = function (didAgreeLocal) {
                console.log(`submitAgreement`, didAgreeLocal);
            };

            $scope.didAgree = false;
            $scope.agreementDialogVisible = true;

        }

    };
});

I need access to the variable variableInTranscludedChildScope mentioned in the code (the checkbox), but since it's inside the transcluded content, it has a separate scope (it's a child to agreementDialog’s scope and a sibling to myapp-dialog-window-modal’s scope). What's the best way of accessing it?

2
  • have you tried using bindings or even events? Commented May 4, 2018 at 7:44
  • @PanosK What do you mean by bindings? I'd like to avoid events. Commented May 4, 2018 at 11:45

1 Answer 1

1
ng-model="smth.variableInTranscludedChildScope"

controller: function ($scope) {
  $scope.smth = {};

  // you can access $scope.smth.variableInTranscludedChildScope here
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.