NG-模式自定义指令角 [英] ng-model for the custom directive Angular
问题描述
问题的问题,
我有一个自定义的日期选择器的指令,并希望链接NG-模型,它在视图中。
I have a custom datepicker directive and want to link ng-model to it in the view.
<div my-date-picker ng-model="date">
{{date}}
</div>
在NG-模型{{日期}}不显示任何人都可以告诉我什么我做错了。
the ng-model {{date}} does not display can anyone please tell me what i am doing wrong
我有plunker创建 http://plnkr.co/edit/bWpNITdjBLZJO1p221xe?p = preVIEW 。
I have plunker created http://plnkr.co/edit/bWpNITdjBLZJO1p221xe?p=preview.
推荐答案
在使用&LT; DIV我-日期选择器NG模型=日期&GT;
日期选择器dirctive
you are using <div my-date-picker ng-model="date">
datepicker dirctive
这意味着你要这个div中取代,由模板让你的 {{日期}}
不再存在了由模板替换指令。
that means your going to replace inside of this div, by the template in the directive so your {{ Date }}
is no longer there its replaced by the template.
如果ü把 {{}日期}
之外的div它将工作
if u put {{ Date }}
outside of the div it will work
和注意模式是不是日期
应该是日期
怎么把输入的型号名称为日期
检查指令模板
and note that model is not date
it should be Date
coz the model name of the input is Date
check the directive template
template: '<input class="dateInput" is-open="openthis.isOpened" type="text" datepicker-popup="dd-MM-yyyy" ng-model="Date" ng-required="true" />'
或您可以添加 {{}日期}
的指令模板
OR you can add {{ Date }}
to the directive template
template: '<input class="dateInput" is-open="openthis.isOpened" type="text" datepicker-popup="dd-MM-yyyy" ng-model="Date" ng-required="true" />' +
'<span ng-click="open($event)" class="glyphicon glyphicon-calendar calImage"></span>'+
'<h2>{{ Date }}</h2>',
这篇关于NG-模式自定义指令角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!