我在我的应用程序中使用 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
中显示 div
或 p
中的信息一段时间后隐藏此消息?
我知道我必须使用 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/