小编Ser*_*rgi的帖子

双向数据绑定在指令中不起作用

我是AngularJS的新手,这是我第一次写指令.

我正在尝试使用AngularJS 使Bootstrap Year Calendar工作.它是一个jQuery插件,用于显示带约会的日历.

我写了这个指令来创建日历:

    app.directive('calendarScheduler', [function () {
        return {
            restrict: 'A',
            scope: {
                calendarData: '='
            },
            link: function (scope, element, attrs, ctrl) {
                element.calendar({
                    enableRangeSelection: true,
                    dataSource: scope.calendarData
                });
            }
        }
    }]);
Run Code Online (Sandbox Code Playgroud)

数据从此控制器传递给指令:

var app = angular.module('App', [])

app.controller('UserCtrl', ['$scope', 
    function($scope) {
        $scope.User = {};
        $scope.User.eventsData = [];

        init();

        $scope.User.addData = function(startDate, endDate) {
            $scope.User.eventsData.push({
                id: 2,
                name: 'Apple Special Event',
                location: 'San Francisco, CA',
                startDate: new Date(2016, 6, 28),
                endDate: new Date(2016, 6, 29) …
Run Code Online (Sandbox Code Playgroud)

twitter-bootstrap angularjs angularjs-directive

5
推荐指数
1
解决办法
403
查看次数