AngularJS Tutorial(11)from w3school
来源:互联网 发布:数据挖掘技术有哪些 编辑:程序博客网 时间:2024/06/05 07:49
AngularJS has its own HTML events directives.
The ng-click Directive
The ng-click directive defines an AngularJS click event.
AngularJS Example
<button ng-click="count = count + 1">Click me!</button>
<p>{{ count }}</p>
</div>
Try it Yourself »
Hiding HTML Elements
The ng-hide directive can be used to set the visibility of a part of an application.
The value ng-hide="true" makes an HTML element invisible.
The value ng-hide="false" makes the element visible.
AngularJS Example
<button ng-click="toggle()">Toggle</button>
<p ng-hide="myVar">
First Name: <input type="text" ng-model="firstName"><br>
Last Name: <input type="text" ng-model="lastName"><br>
<br>
Full Name: {{firstName + " " + lastName}}
</p>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('personCtrl', function($scope) {
$scope.firstName = "John",
$scope.lastName = "Doe"
$scope.myVar = false;
$scope.toggle = function() {
$scope.myVar = !$scope.myVar;
};
});
</script>
Try it Yourself »
Application explained:
The first part of the personController is the same as in the chapter about controllers.
The application has a default property (a variable): $scope.myVar = false;
The ng-hide directive sets the visibility, of a <p> element with two input fields, according to the value (true or false) ofmyVar.
The function toggle() toggles myVar between true and false.
The value ng-hide="true" makes the element invisible.
Showing HTML Elements
The ng-show directive can also be used to set the visibility of a part of an application.
The value ng-show="false" makes an HTML element invisible.
The value ng-show="true" makes the element visible.
Here is the same example as above, using ng-show instead of ng-hide:
AngularJS Example
<button ng-click="toggle()">Toggle</button>
<p ng-show="myVar">
First Name: <input type="text" ng-model="firstName"><br>
Last Name: <input type="text" ng-model="lastName"><br>
<br>
Full Name: {{firstName + " " + lastName}}
</p>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('personCtrl', function($scope) {
$scope.firstName = "John",
$scope.lastName = "Doe"
$scope.myVar = true;
$scope.toggle = function() {
$scope.myVar = !$scope.myVar;
}
});
</script>
Try it Yourself »
- AngularJS Tutorial(11)from w3school
- AngularJS Tutorial(1)from w3school
- AngularJS Tutorial(2)from w3school
- AngularJS Tutorial(3)from w3school
- AngularJS Tutorial(4)from w3school
- AngularJS Tutorial(5)from w3school
- AngularJS Tutorial(6)from w3school
- AngularJS Tutorial(7)from w3school
- AngularJS Tutorial(8)from w3school
- AngularJS Tutorial(9)from w3school
- AngularJS Tutorial(10)from w3school
- AngularJS Tutorial(12)from w3school
- AngularJS Tutorial(13)from w3school
- AngularJS Tutorial(14)from w3school
- AngularJS Tutorial(15)from w3school
- AngularJS Tutorial(16)from w3school
- AngularJS Tutorial(17)from w3school
- AngularJS Tutorial(18)from w3school
- org.hibernate.MappingException: Could not determine type for: String, at table: Elec_SystemDDL, for
- 关于c++中getline(cin,str)在cin之后使用
- 关于EmberJs的一些规范
- Fortran知识点
- MySQL数据库与表创建常用命令
- AngularJS Tutorial(11)from w3school
- Top HTML5 Frameworks in 2015
- 处理乘法取模爆long long 的方法
- POJ 3907 Build Your Home
- Android学习心得(10) --- MAC下Android反编译(2)
- AngularJS Tutorial(12)from w3school
- 积累linux常用的命令
- try-catch-finally的执行顺序
- hihoCoder 1122 二分图二•二分图最大匹配之匈牙利算法