Pass value and unique identifier to function with ng-change with dynamic content

夙愿已清 提交于 2019-12-11 09:33:23

问题


It's a huge title, but it tells about everything, but let me clarify.

I have generator that produces a HTMLstring for an input field (range, checkbox, ...). This massive string then gets placed in the HTML via $templateCache.put('dynamicSettings, htmlString)

Example of a possible string:

var htmlString = "<input type='range' min='0' max='10' value='5' ng-model='sliderBrightness' ng-change='settingsInputChanged(sliderBrightness, 'sliderBrightness')'>";

When I hardcode this string in my HTML file, it works perfectly. The settingsInputChanged() function gets called and 2 parameters are passed, the value and the unique name. The function then saves the value in the localStorage with the keyvalue (2nd parameter).

But when adding the string dynamically, I get this massive error of which I presume has something to do with the fact that I'm passing a String in the ng-change.

rror: [$parse:syntax] Syntax Error: Token 'undefined' not a primary expression at column null of the expression [settingsInputChanged(sliderBrightness,] starting at [settingsInputChanged(sliderBrightness,].

Or maybe it can't handle that I have 2 '-pairs nested.

Can I change my string to not use those '-pairs to pass my string to the function in the ng-change?

来源:https://stackoverflow.com/questions/28646571/pass-value-and-unique-identifier-to-function-with-ng-change-with-dynamic-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!