我知道可以找到类似的问题,但没有答案对我有用。我想显示一个html,例如<h5>Your password is incorrect</h5>
当我在登录时遇到错误的凭据时。所以这段代码应该从 Controller 内部“激活”。这是我的样子:
( function () {
'use strict';
angular
.module( 'app.home' )
.controller( 'ploginController', ploginController );
ploginController.$inject = [ '$scope', '$location', '$state', '$http' ];
/* @ngInject */
function ploginController( $scope, $location, $state, $http ) {
$scope.submit = function () {
$http.post( '/api/v1/person/login', $scope.add, {
headers: {
'Content-Type': 'application/json'
}
} ).then( function ( respSucc ) {
$state.go( 'layout.listcampaigns' );
return respSucc;
}, function ( respErr ) {
//i think code revealing method should be HERE, but how??
return respErr;
} );
};
}
} )();
提前致谢!
最佳答案
您可以使用ng-if
来实现这一点。
首先,在您的 Controller 中:
$scope.loginIncorrect = false;
...
$scope.submit = function () {
$http.post( '/api/v1/person/login', $scope.add, {
headers: {
'Content-Type': 'application/json'
}
} ).then( function ( respSucc ) {
$scope.loginIncorrect = false;
$state.go( 'layout.listcampaigns' );
return respSucc;
}, function ( respErr ) {
$scope.loginIncorrect = true;
return respErr;
} );
};
然后在你的html中:
<h5 ng-if="loginIncorrect">Your password is incorrect</h5>
希望有帮助。
关于javascript - 从 angularjs Controller 调用时显示 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39243579/