评估范围内的表达

时间:2017-07-16 03:58:14

标签: angularjs angularjs-directive

我正在尝试为我的日期选择器创建一个指令,这里是相关的代码。

使用

<date-input open="openCalendar = true">
    <input ng-model="ctrl.model.theDate"
           uib-datepicker-popup="dd-MMMM-yyyy" 
           is-open="openCalendar">
</date-input>

指令

angular
    .module('common.directives')
    .directive('dateInput', function() {

        return {
            restrict: 'E',
            transclude: true,
            scope: {open:'&'},
            template: 'date-input-template',
        };
    });

模板

<script type="text/ng-template" id="date-input-template>
    <div class="input-group">
        <ng-transclude></ng-transclude>
        <div class="input-group-btn">
            <button class="btn btn-default" type="button" ng-click="open()">
                <i class="glyphicon glyphicon-calendar"></i>
            </button>
        </div>
    </div>
</script>    

这个工作一次。如果我第二次尝试打开日历,则不会显示日期选择器。我确定我做错了什么,只是不确定它是什么。

感谢任何建议或指导。

2 个答案:

答案 0 :(得分:0)

ng-click的表达式需要调用open

ng-click="open()"

编辑:您可能希望使用data.openCalendar = true之类的对象来避免原型范围继承问题,或者将openCalendar = true表达式移动到函数中并调用该函数。< / p>

答案 1 :(得分:0)

您应该使用表达式

调用该函数
ng-click="open()">
相关问题