大佬教程收集整理的这篇文章主要介绍了将jQuery插件输入值推送到AngularJS中的模型,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
期望的功能 –
<input my-widget="{{Color}}" type="text"/> <!-- my-widget instantiates my directive --> <h1 style="color:{{Color}}"></h1> <!-- I would like the input value to dump into the attribute's value,in this case {{Color}} -->
这是我到目前为止:
app.directive('myWidget',function(){ var myLink = function(scope,element,attr) { scope.$watch('element',function(){ var value = element.val(); element.change(function(){ console.log(attr.ngModel); // This is currently logging undefined // Push value to attr here? console.log( value + ' was SELEcted'); }); }); var element = $(element).colorPicker(); } return { reStrict:'A',link: myLink } });
app.directive('colorPicker',function() { return { scope: { color: '=colorPicker' },link: function(scope,attrs) { element.colorPicker({ // initialize the color to the color on the scope pickerDefault: scope.color,// update the scope whenever we pick a new color onColorChange: function(id,newvalue) { scope.$apply(function() { scope.color = newValue; }); } }); // update the color picker whenever the value on the scope changes scope.$watch('color',function(value) { element.val(value); element.change(); }); } } });
你会这样使用它:
<input color-picker="color">
这是一个工作的jsfiddle,有几个小小的玩具:http://jsfiddle.net/BinaryMuse/x2uwQ/
jsfiddle使用隔离范围将范围值颜色绑定到传递给颜色选择器属性的任何颜色.我们观察表达式’color’以查看此值何时更改,并适当更新颜色选择器.
以上是大佬教程为你收集整理的将jQuery插件输入值推送到AngularJS中的模型全部内容,希望文章能够帮你解决将jQuery插件输入值推送到AngularJS中的模型所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。