$ watch指令中的元素宽度

时间:2015-05-08 17:21:26

标签: javascript angularjs angularjs-directive

我正在尝试$watch我的元素在指令中的宽度:

appDrct.directive('setWidth', function($interval) {
    return {
        require: '?ngModel',
        link: function($scope, $elm, attr, ngModel) {

            $scope.$watch($elm.parent().width(), function() {
                console.log('Width changed');
            });
        }
     }
})

但它不起作用......我知道我的宽度发生了变化(我尝试用$interval来显示宽度并且它会发生变化)

1 个答案:

答案 0 :(得分:7)

这是你如何做到的,你需要INSERT INTO DFR_DIARY ( SELECT ID_GEN_SEQUENCE.NEXTVAL, sub.* FROM (SELECT A.TRANSACTION_REPORTING_UNIT_CD TRECON_RUC, A.CYCLE_NUMBER_ID, A.CYCLE_DATE CYCLE_STARTED_DT, A.UNIT_DIARY_NUMBER_ID DIARY_NUMBER_ID, 'P' STATUS_CODE, NULL MISSO_INPUT_ID, A.UNIT_DIARY_DATE DIARY_DATE, A.UNIT_DIARY_DATE OPENED_DATE, A.UNIT_DIARY_DATE CERTIFIED_DATE, COUNT(*) TRANS_ACCEPTED_QY, 0 TRANS_REJECTED_QY, 'DFR LOAD' CREATEDBY, SYSDATE CREATEDDATE, NULL, NULL, (SELECT ID FROM UDMIPS.DFR_CYCLE WHERE TRECON_RUC = A.TRANSACTION_REPORTING_UNIT_CD AND CYCLE_NUMBER_ID = A.CYCLE_NUMBER_ID AND CYCLE_STARTED_DT = A.CYCLE_DATE) CYCLE_ID, (SELECT ID FROM UDMIPS.DIARY WHERE TRECON_RUC = A.TRANSACTION_REPORTING_UNIT_CD AND DIARY_NUMBER = A.UNIT_DIARY_NUMBER_ID AND DIARY_DATE = A.UNIT_DIARY_DATE) DIARY_ID FROM UDMIPS.TEMP_TRANSACTION_RESEARCH A WHERE A.TRANSACTION_ERROR_CODE IS NULL AND A.APPLICATION_SYSTEMS_SOURCE_CD = 'P' AND A.TRANSACTION_SERIAL_NUMBER_ID IN (SELECT TRANSACTION_SERIAL_ID FROM UDMIPS.DIARY_TRANSACTIONS) GROUP BY A.CYCLE_NUMBER_ID, A.CYCLE_DATE, A.TRANSACTION_REPORTING_UNIT_CD, A.UNIT_DIARY_NUMBER_ID , A.UNIT_DIARY_DATE ) sub ); 函数表达式:

$watch

Fiddle