Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140584

If my Angular Controller is not using any $scope, then how do i do 2 way data binding in my directive

$
0
0

I have been using Angular without $scope

Controller:

angular
    .module('app')
    .controller('requestController', requestController);

requestController.$inject = ['$location','requestService'];

function requestController($location, requestService) {

    var vm = this;
    //......
    var detail = {}; 
    detail.program.....  
}

HTML page shows value

{{detail.program.code}}    shows   DGAT  on page ...  thus it has value

Pass it into a Directive

<com-code progCode="detail.program.code"></com-code>

Directive in which is supposed to take value in as two way binding

(function () {
    var injectParams = ['customerService', '$sce'];

    var comCode = function (customerService, $sce) {
        return {
            replace: true,
            restrict: "E",
            scope: {
                progCode: "="
            },
            link: function (scope, element, attrs) {

                console.log('scope.progCode',scope.progCode);  // UNDEFINED

            }
        };
    };

    comCode.$inject = injectParams;
    angular.module('app').directive('comCode', comCode)
}());
  1. Why is this undefined?
  2. Is it from the lack of $scope in controller?
  3. Does progCode as 2 way data binding become part of the scope in the directive?

Viewing all articles
Browse latest Browse all 140584

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>