私はテキストボックスの役割を持っています。役割がデータベースに既に存在するかどうかをチェックしたいのですが、私は指向性のuniqueRoleを作成しましたが、その指示にテキストボックス値を渡したいと思います。モデル値をカスタムディレクティブに渡すにはどうすればよいですか?
**HTML**
<input type="text" class="role-textbox" id="rolename" name="rolename" required ng-model="roledetails.name" unique-role send-value="roledetails.name" placeholder="{{::'placeholder.addRole.name'|translate}}">
**Controller**
'use strict';
define([
'angular',
'./module',
], function(angular, directives) {
directives.directive('uniqueRole', function($timeout, $q, restClientTemplate) {
return {
restrict: 'AE',
require: 'ngModel',
scope:{
sendValue: '='
},
link: function(scope, elm, attr, model) {
model.$asyncValidators.usernameExists = function(roledata) {
var defer = $q.defer();
console.log("gng to call controller");
restClientTemplate.execute({
method: 'POST',
url: 'json/check/role',
data: roledata
}).then(function(response) {
roledata = response.results;
defer.resolve(roledata);
}, function(error) {
defer.reject(error);
});
$timeout(function() {
model.$setValidity('usernameExists', false);
defer.resolve;
}, 1000);
return defer.promise;
};
}
}
});
});
あなたのコントローラ内のテキスト値に結合するディレクティブで
scope.sendValue
まだ値が未定義になっているのを助けてください。 –