1. 程式人生 > >AngularJS之ng-if指令

AngularJS之ng-if指令

圖片 attr user clas javascrip 我們 scores 對象 name

1、問題背景

AngularJS利用ng-if指令來判斷對象元素是否為空

2、實現源碼

<!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://blog.csdn.net/jiangjunshow

AngularJS之ng-if指令