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

标签 javascript html angularjs codeigniter

我在我的应用程序中使用 codeigniter 和 angularjs。当我以 Angular 形式添加新人时,如果插入人成功/失败,我会从 codeigniter Controller 收到消息。 Angular Controller 的代码块:

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 Angular 服务,如下所示:

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

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

如果您使用 $timeout,请不要忘记将其注入(inject) Controller 中。

关于javascript - 使用 angularjs+codeigniter 成功添加用户时在 html 中显示消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33394749/

相关文章:

javascript - 如何在 ionic 中的特定页面实现移相器游戏

javascript - react native : I have a question with this React

html - 如何使用css将div中的内容居中

javascript - 在 ajax 查询的结果上添加和触发 bootstrapvalidator

javascript - Angular Google Maps - 显示两个数据模型的坐标

javascript - 使用 ng-bind-html 和默认内容操作内容

angularjs - 如何使用具有构造函数参数的 TypeScript 类定义 AngularJS 工厂

javascript - 如何创建 "Magnet Links"

javascript - 按值|文本查找选择索引

javascript - 无法在 Sencha 中使用 ajax.request