splincodewd
@splincodewd
Developer

Почему не работает ng-blur?

<div class="compliteinfo">
	<div ng-repeat="field in $ctrl.fields">
	
		<div class="input-field col s12" ng-if=" field.type === 'textarea' ">
			<textarea id="field-{{field.id}}" class="materialize-textarea">
				
			</textarea>
			<label for="field-{{field.id}}">{{ field.title }}</label>
		</div>

		<div class="input-field col s12" ng-if=" field.type === 'textfield' " >
		 	<input type="text"  ng-blur="$ctrl.saveData">
		 	<label for="field-{{field.id}}">{{ field.title }}</label>
		</div>

	</div>
</div>

Контроллер
export default ($scope, $element, $attrs) => { 

	let entity = $scope.$ctrl.data;
	let { executeEvents } = $Registry;

	let processStepId = entity.processstepid;
	let entityid = entity.entityId;
	let idInPool = entity.idInPool;

	executeEvents.requestWidgets({
	  'name': 'none', 
	  'sendObject': {'entityGet': [processStepId, entityid, idInPool]},
	  'mycallback': function(answer){

	  	let data = answer.data;
	  	console.log(data)
	  	$scope.$ctrl.fields = data.fields; // сюда занесли свои элементы и они выводятся

	  }
	});

        $scope.$ctrl.saveData = function() {alert('так тоже не работает');}

	$scope.saveData = function(){
		console.log("saveData")
		alert(1)
	}

}


У меня выводятся инпуты и текстовые поля, если типы совпадают в ng-repeat, но почему-то не срабатывает простейший ng-blur, а мне ведь нужно как-то задать событие для этого поля, что делать?
  • Вопрос задан
  • 562 просмотра
Решения вопроса 1
miraage
@miraage
Старый прогер
Note: As the blur event is executed synchronously also during DOM manipulations (e.g. removing a focussed input), AngularJS executes the expression using scope.$evalAsync if the event is fired during an $apply to ensure a consistent state.


Все выражения выполняются в контексте $scope. Соответственно, Angular пытается вызвать $scope.alert(), а не window.alert.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы