我创建了这个jsbin,其中有fieldGroup2 个字段。有一个按钮AddRow在按下时调用,我试图动态地将另一个字段添加到fieldGroup.
这可以用 Formly 实现吗?此示例是它在我的解决方案中的工作方式的简化版本。我将从 Rest 调用中获得我需要的各种字段类型的列表。此调用返回的任何内容都将是需要添加到fieldGroup. 从小处开始......我只是想添加一个基于按钮点击的字段。
我需要使用链接函数来操作 DOM 的某些元素,但为此我需要使用服务。在控制器功能中,我知道如何做到这一点,但在链接功能中我不知道如何实现这一点。
--编辑-- 让我说得更清楚:
我正在使用带有传单的角度形式。link但在传单中,事件必须按如下方式进行:
link: function($scope) {
$scope.to.marker.on('dragend', function(eventArguments) {
var newPosition = eventArguments.target.getLatLng();
$scope.model.geocodes = newPosition;
});
}
Run Code Online (Sandbox Code Playgroud)
问题是我需要为此注入服务。在 angular-formly (http://docs.angular-formly.com/docs/formlyconfig)中,它向我表明我可以在 上注入服务controller: function($scope),但不要给我一种方法来在link我上做同样的事情更改$scope.model.geocodes链接中的 ,它不会触发watcher我在custom-template.
我希望我已经说清楚了。
我的表单有一些需要过滤器的字段.例如,有一个SSN字段.
我目前正在检查用户是否输入了正确的模式(并在需要时显示验证错误).但是,这需要用户自己输入连字符.我想要做的是在用户输入数字时自动添加连字符.
我将如何完成这样的事情?我已经为SSN字段创建了自定义类型.也许在这个自定义领域的控制器?
我的字段包装器将鼠标悬停时将普通文本转换为输入,i还有一个目录,在打开时将焦点设置在该字段上.
现在我希望该字段保持打开,只要我专注于该字段并且如果焦点变为假,则转换回正常文本.有没有办法做到这一点?
包装:
template: [
'<div ng-hide="to.editorEnabled" >',
'<div ng-mouseover="to.editorEnabled=true">',
'{{to.label}}</br>',
'{{to.value}}',
'</div>',
'</div>',
'<div focus-me="to.editorEnabled" ng-show="to.editorEnabled">',
'<formly-transclude></formly-transclude>',
'</div>'
].join(' ')
Run Code Online (Sandbox Code Playgroud)
焦点指令:
app.directive('focusMe', function($timeout, $parse) {
return {
link: function(scope, element, attrs) {
var model = $parse(attrs.focusMe);
scope.$watch(model, function(value) {
console.log('value=',value);
if(value === true) {
$timeout(function() {
element[0].firstElementChild.focus();
});
}
});
}
};
});
Run Code Online (Sandbox Code Playgroud)
形式领域:
key: 'textField',
type: 'input',
templateOptions: {
label: 'Text',
type: 'text',
value:vm.model.textField
},
watcher: {
listener: function(field, newValue, oldValue, scope, stopWatching) {
if(newValue) {
if(!newValue …Run Code Online (Sandbox Code Playgroud)