0

With Kendo UI component in Angularjs, for example:

<input kendo-date-picker="myDatePicker"
       ng-model="dateString"
       k-ng-model="dateObject"
       style="width: 100%;" />

I am able to access the date picker in javascript with the variable $scope.myDatePicker

Now, the problem is, this date-picker comes with a wrapper with the tag ng-switch-when.

<div ng-switch="userSelection.code">
   <div ng-switch-when="JUST_DEMO">
      <input kendo-date-picker="myDatePicker"
         ng-model="dateString"
         k-ng-model="dateObject"
         style="width: 100%;" />
   </div>
</div>

With this, in the javascript, the variable $scope.myDatePicker becomes 'undefined', even though after the flag JUST_DEMO is turned on subsequently.

So my question is, how to fix this? I need to access $scope.myDatePicker in javascript to manually open the datepicker in the code.

P.S.:

I think I found a working approach: using $compile in the databound event.

2 Answers 2

1

i don't see any code for ng-switch , not sure if it's there in your tag :

<div ng-switch="myVar">

ng-switch is evaluated against myVar variable in abve code snippet.

I suggest you use ng-switch as follows :

declare a scope variable with some sort of flag to base your ng-switch on

$scope.datePickerParent = {};// some object
datePickerParent .JUST_DEMO = true/false;
datePickerParent.myDatePicker = ''; //assign some value
<td ng-switch on="datePickerParent.showNgSwitch"> 

    <div ng-switch-when="datePickerParent.JUST_DEMO">
   <input kendo-date-picker="datePickerParent.myDatePicker"
       ng-model="dateString"
       k-ng-model="dateObject"
       style="width: 100%;" />
   </div>
   </td>

Also have a look at this SO post

Also try to use $parent to access scope variable, ng-switch creates it's own scope

Sign up to request clarification or add additional context in comments.

6 Comments

Sorry, my mistake that overlooks the ng-switch (just edited). But i think the problem is, at first, since the ng-switch-when condition isn't fulfilled, so the html isn't created on loaded. And for some reason, although it is fulfilled afterwards, the $scope variable is still undefined....
what i meant to convey in my response is may be ng-switch-when can't directly access JUST_DEMO IMHO , it has to be via ng-switch variable i.e. userSelection.JUST_DEMO as referred in linked post
hm...understand your words now. But I am afraid this may not be the cause. As I do see the kendo-date-picker being rendered on the page. Just that, I couldn't access it with the $scope variable...
try to use $parent to access scope variable, ng-switch creates it's own scope
did you find a solution ?
|
0

I found the solution:

<div ng-switch="userSelection.code">
   <div ng-switch-when="JUST_DEMO">
      <input kendo-date-picker="myKendo.myDatePicker"
         ng-model="dateString"
         k-ng-model="dateObject"
         style="width: 100%;" />
   </div>
</div>

instead of using the normal "myDatePicker" variable, wrap it in another object, such as myKendo.

So, in javascript, this can be accessed with $scope.myKendo.myDatePicker.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.