我想在alertForm
指令中调用loginForm
指令。我想去哪里打电话' alertForm'指令' loginForm'突出显示为//i want to call here
alertForm指令
angular.module('myApp')
.directive('alertForm', function () {
return {
templateUrl: 'app/directives/alert/alertForm.html',
restrict: 'E',
scope: {
topic: '=topic',
description: '=description'
},
controller: function($scope) {
$scope.words = [];
this.showAlert = function() {
$scope.description.push("hello");
};
}
};
});
loginForm指令
angular.module('myApp')
.directive('loginForm', function() {
return {
templateUrl: 'app/directives/loginForm/loginForm.html',
restrict: 'E',
scope: {
successCallback: '&',
errorCallback: '&',
emailField: '='
},
link: function (scope, element, attrs) {
},
controller: function ($rootScope, $scope, authenticationService) {
$scope.loginFormData = {};
$scope.inProgress = false;
$scope.onLogin = function (form) {
if (form.$valid) {
$scope.inProgress = true;
authenticationService.loginUser('password', $scope.loginFormData).then(function () {
$scope.successCallback({formData: $scope.loginFormData});
}, function (err) {
$scope.inProgress = false;
if (err.message) {
**// i want to call here**
}
});
}
}
}
};
});
答案 0 :(得分:1)
在app/directives/loginForm/loginForm.html
:
<alertForm topic="something" description = "something" ng-if="showAlert"></alertForm>
现在在loginForm指令的控制器中: //我想在这里打电话 使用
$scope.showAlert = true;
注意:您可以使用一些变量来设置alertForm中的主题和描述。
答案 1 :(得分:1)