这是我在angularjs中编写的简单指令。我的指令很简单,$ http获取值和设置变量。当我运行此指令时,我有一个$ digest错误。为什么?我使用Angularjs 1.2.13。
我的代码:
link77.directive('dbLabel', ['$http', 'remoteconf', function ($http, remoteconf) {
return {
restrict: 'EA',
require: 'ngModel',
replace: true,
template: '<legend>{{valdb}}</legend>',
link: function (scope, elem, attrs, ctrl) {
var table = attrs.dbTable;
var field = attrs.dbField;
var where = attrs.dbWhere;
scope.$apply(function () {
$http({
method: 'POST',
url: remoteconf.init.appApiEntryPoint + attrs.ngModulo + '/api/service.php?x=getdbval',
data: {
xtable: table,
xfield: field,
xwhere: where
}
}).success(function(data, status, headers, config) {
scope.valdb = data.status;
});
});
}
}
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script>
<db-label db-table="users" db-field="lastname" db-where="where id = {{user.id}}"/>