我正在尝试为表单中的自定义字段创建一个指令.我能够创建指令但不能更新范围.
有关问题的更多信息,请参阅Plunker演示
问题我面临的是,当我提出我得到的自定义字段NG-模型的价值形态为空或未定义.因为双向绑定不起作用
你会看到,当我们从父将更新指令范围,但是当你将一个自定义字段不会更新这是使用父范围输入字段和双向绑定后,将无法正常工作更新更新范围
这是我的文件
users.html
<custom-field ng-repeat="(key,field) in custom_fields" form="userForm" ng-model="user.custom_field[field.id]" fielddata="field"></custom-field>
Run Code Online (Sandbox Code Playgroud)
app.js
app.directive('customField', function () {
var directive = {};
directive.restrict = 'E';
directive.templateUrl = 'app/modules/custom_fields/views/custom_field_directive.html';
directive.scope = {
ngModel: "=",
mydata: "<fielddata",
form: "<"
}
return directive;
});
Run Code Online (Sandbox Code Playgroud)
custom_field_directive.html
<div layout="row" layout-xs="column">
<div flex >
<!-- Custom input field html [Required Field] -->
<md-input-container class="md-block" ng-if="mydata.type == 'input' && mydata.is_required==1">
<label>{{mydata.field_name}}</label>
<input name="{{mydata.slug}}" ng-model="ngModel" ng-required="!ngModel">
<div ng-messages="form[''+mydata.slug+''].$error" ng-show="form[''+mydata.slug+''].$touched" role="alert">
<div ng-message="required">
<span>{{mydata.field_name}} …Run Code Online (Sandbox Code Playgroud) html javascript angularjs angularjs-directive angularjs-scope
我需要获取要在下面使用的输入值,该怎么做?我试图喜欢这个,但错误说
未定义的变量:名称
<div class="col-md-10 col-md-offset-1">
<input id="name" type="text" name="name" />
</div>
<div class="col-md-10 col-md-offset-1">
@php
$nameValue=$_GET['name'];
@endphp
<input id="name2" type="text" name="name2" value="{{$nameValue}}" />
</div>
Run Code Online (Sandbox Code Playgroud)