我创建了两个指令并应用于元素。当我在selectControlDir中警告ng-model时,它在alert中获取值,而在cbqControlDir中,我在alert中得到未定义。
我在加载和更改cbqControlDir时进行了一些ajax调用,我在url中传递了这些值,但在页面加载时在url中未定义。
的的index.html
<div class="row">
<div class="form-group">
<label class="col-sm-5 control-label" for="VehicleOriginalCost">{{questions[$state.current.name].VehicleOriginalCost.QuestionData._text}}</label>
<div class="col-sm-6">
<input type="text" id="VehicleOriginalCost" class="form-control" name="VehicleOriginalCost" ng-model="answers.VehicleOriginalCost" data-que-obj="questions[$state.current.name].VehicleOriginalCost.QuestionData" required text-control-dir cbq-dir number-only>
</div>
</div>
<span class="form-error" ng-show="submitted && DTOstep1.VehicleOriginalCost.$error.required">This field is required.</span>
</div>
controlDirective.js
function textControlDir()
{
return {
transclude: true,
restrict: 'A',
priority: 100,
scope: {
ngModel: '=',
queObj: '='
},
link: function (scope, element, attrs) {
if (angular.isUndefined(scope.ngModel))
{
scope.ngModel = scope.queObj._pageAttributes.defaultValue;
}
}
};
}
function cbqControlDir($http)
{
return {
transclude: true,
restrict: 'A',
priority: 200,
require: ngModel,
link: function (scope, element, attrs) {
//http call
//url apc.php/ngModel
}
};
}
如何访问指令中的更新范围值?
Plunker for code