標籤:route dir cti names 第一個 param repeat 無法 ctr
-----------------------------------------------------------------------------------------------------------
html中賦值:<button ng-click="showColor(‘green‘)">變色</button>
js中取值:
$scope.showColor=function($routeParams){
alert($routeParams)
}
-----------------------------------------------------------------------------------------------------------
html中賦值:<a href="#/detail/{{ book }}"> book={{ book }}<br/>
js中取值:$routeParams.book
book為屬性名稱
------------------------------------------------------------------------------------------------------------------------------------------
瀏覽器中賦值:
http://localhost:8080/test/index.html#/hello
app.js中取值
var app =angular.module(‘bookStoreApp‘,[
‘bookStroreCtrls‘
]);
app.config(function($routeProvider){
$routeProvider.when(‘/hello‘,{
templateUrl:‘html/hello.html‘,
controller:‘HelloCtrl‘
})
.when(‘/hello‘,{
templateUrl:‘html/form/testFormCtrl.html‘,--------跳轉到對應的html頁面
controller:‘TestFormCtrl‘---------尋找對應的controller
})
.when(‘/list‘,{
templateUrl:‘html/bookList.html‘,
controller:‘BookListCtrl‘
})
.when(‘/detail/:book‘,{
templateUrl:‘html/detail.html‘,
controller:‘BookDetailCtrl‘
})
.otherwise({
redirectTo:‘/hello‘
})
});
-----------------------------------------------------------------------------------------------------------
Js中賦值:
/ng-bind在index.html首頁的時候代替{{}}取值,在其他頁面均用{{}}取值即可
1簡單的賦值
$scope.hello="你好";
2 外層.內層賦值
$scope.hello={
someText:‘示範特性二:示範模組化‘
};
3 集合的賦值
$scope.books=[
{title:"書1",author:"作者1"},
{title:"書2",author:"作者2"},
{title:"書3",author:"作者3"}
]
$scope.names=[‘zhangsan‘,‘lisi‘,‘wangwu‘];
html中取值:
1簡單的取值{{hello}}輸出"你好"
2外層.內層取值{{hello.someText}}輸出“示範特性二:示範模組化”
3 集合取值
<div ng-controller="listCtrol">
<table>
<tr ng-repeat=‘name0 in names‘>
<td >{{id}}-{{name}}—{{name0}}-{{department}} from {{names}}</td>
</tr><br/>
</table>
</div>
<ul>
<!-- 此處標籤內放兩個ng-repeat不會報錯,只是起作用而已。當兩個同時出現時,標籤只認第一個 -->
<li ng-repeat="book in books" ng-repeat="name in names">
<a href="#/detail/{{ book }}"> book={{ book }}<br/>
title={{book.title}}<br/>
author={{book.author}}<br/>
names={{names}}<br/>
name={{name}}<!-- 此處無法顯示 -->
</a>
</li>
html與js的取值,賦值