0
내 기본 데이터를 업데이트하기 위해 내부 편집을 한 후 컨트롤러에서 함수를 실행하려고하는데 트리거하지 않습니다 ... 이유를 이해할 수 없습니다 . 올바른 범위에 있는지 어떻게 확인할 수 있습니까? 나는 Meanjs를 사용하고있다.컨트롤러에서 angularJs 지시문에서 트리거 할 함수가 없습니다.
테스트로서 나는 나의 컨트롤러에서 testar() 함수를 트리거하려고하고있다.
angular.module('customers').directive('editInPlace', [
function() {
return {
restrict: 'E',
scope: {
value: '='
},
template: '<span ng-click="edit()" ng-bind="value"></span><input ng-model="value"></input>',
link: function (scope, element, attrs) {
// Let's get a reference to the input element, as we'll want to reference it.
var inputElement = angular.element(element.children()[1]);
// This directive should have a set class so we can style it.
element.addClass('edit-in-place');
// Initially, we're not editing.
scope.editing = false;
// ng-click handler to activate edit-in-place
scope.edit = function() {
scope.editing = true;
// We control display through a class on the directive itself. See the CSS.
element.addClass('active');
// And we must focus the element.
// `angular.element()` provides a chainable array, like jQuery so to access a native DOM function,
// we have to reference the first element in the array.
inputElement[0].focus();
};
// When we leave the input, we're done editing.
inputElement.prop('onblur', function() {
scope.editing = false;
element.removeClass('active');
console.log("trigg");
scope.$apply("testar()");
});
}
};
}
]);
angular.module('customers').controller('CustomersController', ['$scope', '$stateParams', '$location', 'Authentication', 'Customers',
function($scope, $stateParams, $location, Authentication, Customers) {
$scope.authentication = Authentication;
// Create new Customer
$scope.create = function() {
// Create new Customer object
var customer = new Customers ({
name: this.name,
firstName:this.firstName
});
$scope.testar = function() {
console.log("jojjemen från controller");
}
}
]); 당신이 당신의 지시자를 포함 할 때, 당신은 컨트롤러 기능을 전달할 필요는 HTML에 다음
scope.controllerFunction();
을 그리고 :
scope
{
value: '=',
controllerFunction: '='
}
그리고 당신의 링크 기능에
당신이 전화 :
매력처럼 작동합니다 :-) 많은 감사합니다! – user3157746