AngularJS之ng-if指令

前端之家收集整理的这篇文章主要介绍了AngularJS之ng-if指令前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1、问题背景

AngularJS利用ng-if指令来判断对象元素是否为空


2、实现源码

@H_404_21@<!DOCTYPE html> <html ng-app="ifApp"> <head> <Meta charset="UTF-8"> <title>AngularJS之ng-if指令</title> <script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script> <script> var app = angular.module("ifApp",[]); app.controller("ifController",function($scope){ $scope.person = { name:{ username:"张三",sex:"男",age:"23" },scores:{ item:"语文",score:"123" } }; }); </script> </head> <body ng-controller="ifController"> <div ng-if="person != null"> <div ng-repeat="p in person"> <div ng-if="person.name != null"> <label>{{p.username}}</label> </div> </div> </div> </body> </html>
3、实现结果

原文链接:https://www.f2er.com/angularjs/148862.html

猜你在找的Angularjs相关文章