Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing directive attribute in controller

I'm new to angular and I'm using angular-bootstrap-datetimepicker, and I want to access its directive attribute data-datetimepicker-config in my controller

<datetimepicker data-ng-model="data.date" data-datetimepicker-config="{ dropdownSelector: '.dropdown-toggle' }"></datetimepicker>

I have a select component which contains values like daily monthly and yearly and I want to change the minView value of my datetimepicker with the select value.

How can I do that ?

like image 463
azelix Avatar asked Jan 29 '26 17:01

azelix


1 Answers

The documentation states that

you can pass configuration options as a function or an object.

So you should simply define the config object in your scope or controller and then pass it as value of the data-datetimepicker-config attribute. Here's how you could go about it:

$scope.pickerConfig = { dropdownSelector: '.dropdown-toggle' };

Then in your view:

<datetimepicker data-ng-model="data.date" data-datetimepicker-config="pickerConfig"></datetimepicker>

Basically, changes in pickerConfig will be applied to datetimepicker directive. It is as simple as that.

like image 50
rzelek Avatar answered Jan 31 '26 06:01

rzelek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!