简体   繁体   中英

angularjs: How to set the value of a kendo color picker inside kendo template?

I have the following rowTemplate for my kendo grid:

<script id="gridTemplate" type="text/x-kendo-template">
<tr data-uid="#= uid #">
    <td>
        <input type="color" kendo-color-picker k-palette="controller.colors" value="'#=color#'" on-change="controller.changeColor()" />
    </td>
</tr>

My problem is that I want to set the value of the color picker from the dataItem.color property. With the syntax above I get the following message: The specified value "'#0000ff'" does not conform to the required format. The format is "#rrggbb" where rr, gg, bb are two-digit hexadecimal numbers. The specified value "'#0000ff'" does not conform to the required format. The format is "#rrggbb" where rr, gg, bb are two-digit hexadecimal numbers.

If I change it to value="#=color#" (without the single quotes) then I get:

Error: [$parse:lexerr] Lexer Error: Unexpected next character  at columns 0-    0 [#] in expression [#00ff00].
http://errors.angularjs.org/1.4.0/$parse/lexerr?p0=Unexpected%20next%20character%20&p1=s%200-0%20%5B%23%5D&p2=%2300ff00
Cause: <input type="color" kendo-color-picker="" k-palette="trend.colors" value="#00ff00" on-change="trend.changeColor()">
{anonymous}()@columns 0-0 [#] in expression [#00ff00].
{anonymous}() (http://errors.angularjs.org/1.4.0/)$parse/lexerr?p0=Unexpected%20next%20character%20&p1=s%200-0%20%5B%23%5D&p2=%2300ff00

I tried to move the template in the angular code and use function(dataItem) but resulted with the same errors. Any help will be much appreciated.

I was receiving the same error when trying to set the Value field. Instead, I tried to set the view model/$scope property that represents the color palette.

Kendo Color Picker control

        <input kendo-color-picker ng-model="dashboardBuilder.templateOptions.titleBackgroundColor" k-palette="'websafe'" k-preview="false" k-input="true" k-opacity="true"/>

On the load event of the controller set the color palette's property as so

 vm.templateOptions = {
            titleBackgroundColor: '#000000'
        };

That will default your picker to your color of choice.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM