login
및 rankSelector
의 두 지시문을 만들었습니다. 아래 코드에서 볼 수 있듯이 로그인은 rankSelector
내부에서 사용됩니다. 그러나이 두 지시어 사이의 통신을 구현하는 적절한 방법은 무엇인지 모르겠습니다. rankSelector
은 login
의 부모이며 login
지시어에서 몇 가지 변경 사항이 언제 발생하는지 알아야합니다. ATM 에있는 컨트롤러를 사용합니다. 방법은 login
이며 부모 지시문에 변경 사항을 알릴 필요가있을 때 호출합니다. 코드는 다음과 같습니다 :angularJS의 paren-child 지시어 사이의 통신
<script type="text/ng-template" id="rankSelector.html">
<form name="rankings" novalidate>
<div>
<div login></div>
<!-- if passwords match show this -->
<input type="text" ng-model="someOtherField" name="someOtherField" ng-show="passwordsMatch" ng-hide="!passwordsMatch" />
</div>
</form>
</script>
그리고 내 지침 : 여기 옳은 일을하는 경우
가app.directive("login", [
function(loginService) {
return {
templateUrl: "login.html",
replace: true,
require: "?^rankSelector",
scope: true,
link: function(scope, elem, attrs, ctrl) {
scope.$watch("confirmPassword", function(newValue, oldValue) {
// also how in here I can check if scope.password is $valid without douing checks manually?
ctrl.passwordsMatch(scope.password && scope.password === scope.confirmPassword);
});
}
};
}
]);
app.directive("rankSelector", [
function(rankingsService, $rootScope) {
return {
templateUrl: "rankSelector.html",
replace: true,
controller: ["$scope",
function($scope) {
this.passwordsMatch = function(showConfirm) {
$scope.passwordsMatch = showConfirm;
}
}
],
scope: true,
link: function(scope, elem, attrs) {
scope.passwordsMatch = false;
}
};
}
]);
확실하지 login
지시문을 인식 할 필요가로 어떤 컨트롤러가 삽입 될지를 결정해야한다. 내가 알아야 할이 접근법에 명백한 문제가 있습니까?
도 login
지시문 내에서 $watch
의 전화 번호부가 $valid
인지 확인하려면 어떻게해야합니까?