2

Im trying to get the data from a response on http promise and set this data on attr from custome diretive, but always get a undefined data on my directive

promiseComboBox.then((response) =>
    {
        $scope.comboBoxTipoParking = response; //get data
    });

module.directive('comboBox', ['$rootScope', function($rootScope){
    return {
        restrict    : 'E',
        scope       : {
            data  : '=',
            label : '='
        },
        templateUrl : '/Scripts/components/select/select.html',
        link        : function(scope, element, attrs)
        {            
            console.log(attrs);//get here but undefined
            scope.label = attrs.label;


            $('.select2').select2({
                width           : '100%',
                dropdownParent  : $('.modalFocusInput')
            });
        }
    }
}]);

<combo-box label="Parqueadero" data="{{comboBoxTipoParking}}">
</combo-box>

//passing the result from http request

1 Answer 1

1

One can use attrs.$observe

app.directive('comboBox', function(){
    return {
        restrict    : 'E',
        scope       : false,
        templateUrl : '/Scripts/components/select/select.html',
        link        : function(scope, element, attrs)
        {            
            console.log(attrs);//get here but undefined
            attrs.$observe("boxData", function(value) {
                console.log(value);
            });
        }     
    }
});
<combo-box label="Parqueadero" box-data="{{comboBoxTipoParking}}">
</combo-box>

Be careful when using the identifier data as an attribute. Directive normalization strips the data- prefix.

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.