admin管理员组文章数量:1289832
I have a date picker widget, and I want to pass the picked date to the controller. I have this script snippet in my view:
<div id="datepicker"></div>
<script type="text/javascript">
$('#datepicker').datepicker();
$('#datepicker').datepicker()
.on('changeDate', function(ev){
alert(ev.date);
});
</script>
How to send this "ev.date" to the controller?
I want it to affect controller variable so this change is then picked up by a directive and dom is modified in the directive.
I have a date picker widget, and I want to pass the picked date to the controller. I have this script snippet in my view:
<div id="datepicker"></div>
<script type="text/javascript">
$('#datepicker').datepicker();
$('#datepicker').datepicker()
.on('changeDate', function(ev){
alert(ev.date);
});
</script>
How to send this "ev.date" to the controller?
I want it to affect controller variable so this change is then picked up by a directive and dom is modified in the directive.
Share Improve this question asked Jun 2, 2013 at 19:02 LucasSeverynLucasSeveryn 6,2728 gold badges41 silver badges66 bronze badges 2- You can try using the angular event bus and fire an event. – Adrian Mitev Commented Jun 2, 2013 at 19:05
- This tells me nothing :( I only started with angularjs yesterday. Can you post an example on how to send data to a variable in controller? – LucasSeveryn Commented Jun 2, 2013 at 19:06
1 Answer
Reset to default 10You can do something like this:
$('#datepicker').datepicker()
.on('changeDate', function(ev){
//get a hold of controller and scope
var element = angular.element($('#datepicker'));
var controller = element.controller();
var scope = element.scope();
//as this happends outside of angular you probably have to notify angular of the change by wrapping your function call in $apply
scope.$apply(function(){
scope.updateDateFunction(ev.date);
});
});
See: http://docs.angularjs/api/angular.element
本文标签: javascriptHow to update controller variable from jqueryStack Overflow
版权声明:本文标题:javascript - How to update controller variable from jquery? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741399925a2376602.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论