成功时在html中显示消息,使用angularjs + codeigniter添加用户

Show message in html when successed add user with angularjs+codeigniter

本文关键字:angularjs 使用 codeigniter 用户 添加 消息 html 显示 成功      更新时间:2023-09-26

我在我的应用程序中使用codeigniter和angularjs。当我以角度形式添加新人员时,如果插入人员成功/失败,我会从代码点火器控制器接收消息。来自角度控制器的代码块:

request.success(function (data) {
    $scope.patientForm.$setPristine();
    $rootScope.message = data; //0 - ok, 1-fail
    if($scope.message)
        // some code
});

$scope.message = 0时,如何在html中以divp显示信息,并在一段时间后隐藏此消息?我知道我必须使用ng-show,但我不知道怎么做。

你可以这样使用 ng-show:

<p ng-show="!message">Information text</p>

ng-show 中的表达式为真时,它将显示 p 元素。在这种情况下,它将显示message何时是假的。所以当$scope.message的值设置为 0 时,将显示 p 元素。

要在一段时间后隐藏消息,您可以使用$timeout角度服务,如下所示:

$timeout(function () {
    $scope.message = newvalue;
}, 3000);

这将在 3000 毫秒后更改 $scope.message 的值。

如果您使用$timeout,请不要忘记将其注入控制器。

你只需要在HTML代码中使用ng-show,例如:

<div ng-show="message == 0"> your information here</div>