I really hope it is okay to post here ... I spent some time browsing these
forums to see that others post questions here, so if this is not
appropriate, please let me know and I will remove it.
I am very new to angular, and am trying to get the hang of directives. In a
specific scenario, I am using a third party library (*Kendo UI*, from
*Telerik*) and I need to override one of its default behaviors for a
specific widget. By default, the widget binds using *ng-model* or their own
custom *k-ng-model* to attach to a property on your *$scope*. This is okay
for some situations, but it only returns a string value, not the full
object value. To get that, I have to use another function, *dataItem()*,
when the widget's value changes. In jQuery this was pretty simple to do,
and I can do it well enough in angular, but the properties for the widget
are their own stand alone function that do not have knowledge of my
controller, scope, etc.
So to get around this, I am trying to create a custom directive. I have
accomplished everything except actually assigning the value I need to my
model on my controller's scope. This is the code I have so far.
.directive("kDataItem", function () {
return {
restrict: "A",
link: function (scope, element, attributes) {
scope.$on('kendoWidgetCreated', function (event, widget) {
if ($.compare(widget.element, element)) {
widget.bind('change', function (e) {
scope.$apply(function () {
scope.Model.Group = e.sender.dataItem().toJSON();
});
});
}
})
}
}
});
This is how it is used;
<select
kendo-drop-down-list
k-options="kendoDropDownListOptions"
k-data-item="Model.Group">
</select>
This is my problem, I have to type *scope.Model.Group* directly. This is
obviously not good, as it means I have to hard-code the field. That is, for
very clear and obvious reasons, undesirable, because I intend to use this
directive for all sorts of properties.
I am having a hard time getting this directive to actually send data to my
real model using only variable information I can retrieve within the
directive. Logically, I thought this would do it;
scope[attributes['kDataItem']] = // value;
But that actually gives me a unique looking literal, that looks more like
this;
{
Model: {
Id: "object/id",
Name: "object name",
// other properties
},
Model.Group : {
// value from my widget
}
}
So I am at a loss, now. I cannot figure out why this is happening, or what
to do to put the data into the right object without knowing it beforehand
and hard-coding it.
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.