我有一个像这样的满足的div:
Sub LoopThroughFiles()
Dim Wb As Workbook
Dim ws As Worksheet
Dim strFolder As String
Dim strFile As String
strFolder = "c:\temp"
strFile = Dir(strFolder & "\*.xls*")
With Application
.ScreenUpdating = False
.DisplayAlerts = False
End With
Do While Len(strFile) > 0
Set Wb = Workbooks.Open(strFolder & "\" & strFile)
Set ws = Nothing
On Error Resume Next
Set ws = Wb.Sheets("Sheet Name")
On Error GoTo 0
If Not ws Is Nothing Then ws.SaveAs Left$(Wb.FullName, InStrRev(Wb.FullName, ".")) & "csv", FileFormat:=xlCSV
Wb.Close False
strFile = Dir
Loop
With Application
.ScreenUpdating = True
.DisplayAlerts = True
End With
End Sub
在我的控制器中:
<div contenteditable="true" ng-model="name">{{ name }}</div>
<input type="button" ng-click="checkScope()" value="Click me">
单击按钮时,如何使用范围获取contenteditable div的最新值?
答案 0 :(得分:3)
你需要一个指令来处理这个
app.directive('contenteditable', [function() {
return {
require: '?ngModel',
scope: {
},
link: function(scope, element, attrs, ctrl) {
// view -> model (when div gets blur update the view value of the model)
element.bind('blur', function() {
scope.$apply(function() {
ctrl.$setViewValue(element.html());
});
});
// model -> view
ctrl.$render = function() {
element.html(ctrl.$viewValue);
};
// load init value from DOM
ctrl.$render();
// remove the attached events to element when destroying the scope
scope.$on('$destroy', function() {
element.unbind('blur');
element.unbind('paste');
element.unbind('focus');
});
}
};
}]);
你可以像这样使用它
<div contenteditable="true" ng-model="name">{{ name }}</div>
这是一个demo