我有一个指示,根据字段的值显示符号。这附加到一个字段如下:
Option Explicit
Sub RemoveDuplicatesWithReport()
Dim unique() As Variant
Dim ws As Worksheet
Dim x As Long, uidCt As Long, dCol As Long, remCt As Long
On Error GoTo ErrorHandler
'turn off screenupdating/calculation
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
'current sheet
Set ws = ActiveSheet
'column K
dCol = 11
'resize array for counting uniques
ReDim unique(ws.Cells(ws.Rows.Count, dCol).End(xlUp).Row)
'count how many unique values there are (uidCt)
For x = 2 To ws.Cells(ws.Rows.Count, dCol).End(xlUp).Row
If CountIfArray(ws.Cells(x, dCol), unique()) = 0 Then
unique(uidCt) = ws.Cells(x, dCol).Text
uidCt = uidCt + 1
End If
Next x
'count before removal
remCt = WorksheetFunction.CountA(ws.Columns(dCol)) - 1
'remove duplicates
ws.Columns(dCol).RemoveDuplicates Columns:=1, Header:=xlYes
'count after removal
remCt = remCt - (WorksheetFunction.CountA(ws.Columns(dCol)) - 1)
'turn screenupdating/calculation back on
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
ws.Calculate
'display results
MsgBox remCt & " duplicate values were found and removed." & vbCr & uidCt & " unique values remain.", vbInformation, "Remove Duplicates"
Exit Sub
ErrorHandler:
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
MsgBox Err.Number & vbCr & Err.Description
Exit Sub
End Sub
Public Function CountIfArray(lookup_value, lookup_array)
CountIfArray = Application.Count(Application.Match(lookup_value, lookup_array, 0))
End Function
指令如下:
<input type="text" placeholder="" class="text-input" ng-class="example_class" ng-model="exmaple-model" my-directive />
代码已到达module.directive("myDirective", function () {
return {
require: "?ngModel",
link: function (scope, element, attrs, ngModelCtrl) {
/*breakpoints show the line above and below are reached*/
ngModelCtrl.$parsers.push(function (val) {
/* call to function to show symbol, this line is never reached */
}
行,但不再进一步。调试表明虽然ngModelCtrl
看起来正确构建(有函数和值等),但ngModelCtrl
为空 - 长度为0,应该存在的函数不是。
查看Chrome检查器不会产生任何错误。是否有任何理由让$parsers
为空白,或者是否有办法进一步调试该指令?
答案 0 :(得分:2)
您的解析器显示0长度,尝试从解析方法返回一些值并按如下方式使用它:
function parse(value) {
if (value) {
return value.toLowerCase();
}
}
ngModelController.$parsers.push(parse);
答案 1 :(得分:0)
查看https://alexperry.io/angularjs/2014/12/10/parsers-and-formatters-angular.html
您是否尝试将逻辑直接放在“调用函数来显示符号”与调用函数的位置?