簡體   English   中英

自定義指令在Angular JS中不起作用

[英]Custom directive not working in angular js

我在angular js中為日期選擇器使用了自定義指令,但這似乎不起作用。 (包括Angular-resource.js)

代碼:

var myApp = angular.module('myApp',[
    'ngRoute',
    'myAppControllers',
    'ui.bootstrap',
    'ngSanitize',
]);

myApp.directive('jqdatepicker', function () {
    return {
        restrict: 'A',
        require: 'ngModel',
         link: function (scope, element, attrs, ngModelCtrl) {
            element.datepicker({
                dateFormat: 'DD, d  MM, yy',
                onSelect: function (date) {
                    scope.date = date;
                    scope.$apply();
                }
            });
        }
    };
});


<input type="text" class="form-control datepicker" ng-model="formData[field.name.field_name]" jqdatepicker/>

一個小提琴正在工作,但我的代碼沒有

您忘記了ng-app指令來告訴頁面,哪個模塊必須在該模板上工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM