html與js的取值,賦值

來源:互聯網
上載者:User

標籤: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的取值,賦值

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.