select遍历
<body ng-app='myapp' ng-controller='myctl'>
<div class="container">
<h1 class="page-header">angular框架</h1>
<select class='form-control'>
<option value="" ng-repeat='site in sites'>{{site.Url}}</option>
</select>
</div>
</body>
<script>
app = angular.module('myapp', []);
app.controller('myctl', function($scope, $http) {
$http.get('get.php').success(function(res) {
$scope.sites = res.sites;
});
});
</script>
get.php
<?php
$str='{
"sites": [
{
"Name": "菜鸟教程",
"Url": "www.runoob.com",
"Country": "CN"
},
{
"Name": "Google",
"Url": "www.google.com",
"Country": "USA"
},
{
"Name": "Facebook",
"Url": "www.facebook.com",
"Country": "USA"
},
{
"Name": "微博",
"Url": "www.weibo.com",
"Country": "CN"
}
]
}';
echo $str;
?>
ng sql使用.html
<body ng-app='myapp' ng-controller='myctl'>
<div class="container">
<h1 class="page-header">angular框架</h1>
<table class='table table-striped table-bordered table-hover'>
<tr>
<th>编号:</th>
<th>用户名:</th>
<th>密码:</th>
</tr>
<tr ng-repeat='row in rows'>
<td>{{row.id}}</td>
<td>{{row.usename}}</td>
<td>{{row.password}}</td>
</tr>
</table>
</div>
</body>
<script>
app = angular.module('myapp', []);
app.controller('myctl', function($scope, $http) {
$http.get('sql.php').success(function(res) {
$scope.rows = res;
});
});
</script>
json_encode把数组转成json字符串.php
<?php
$servername = "localhost";
$username = "root";
$password = "133nubia022";
$dbname = "myweb";
// 创建连接
$conn = mysqli_connect($servername, $username, $password, $dbname);
$sql = "SELECT * FROM user";
$rst = mysqli_query($conn, $sql);
while($row=mysqli_fetch_assoc($rst)){
$rows[]=$row;
}
$str=json_encode($rows);
echo $str;
?>
ng-disabled方法
<body ng-app='myapp' ng-controller='myctl'>
<div class="container">
<h1 class="page-header">angular框架</h1>
<p>
<button class='btn btn-primary' ng-click='dis()'>禁用</button>
</p>
<div class="form-group">
<label for="">留言:</label>
<textarea class='form-control' ng-disabled='nd'></textarea>
</div>
</div>
</body>
<script>
app=angular.module('myapp',[]);
app.controller('myctl',function($scope,$http){
$scope.dis=function(){
$scope.nd=true;
}
});
</script>
ng-show 指令
<p ng-show="true">我是可见的。</p>
<p ng-show="false">我是不可见的。</p>
ng-hide 指令
<p ng-hide="true">我是不可见的。</p>
<p ng-hide="false">我是可见的。</p>
**
**
**
**
**
**
**
**
**
**
**
**
**