个性化阅读
专注于IT技术分析

angularjs范围

点击下载

本文概述

范围是一个对象,被指定为HTML(视图)和JavaScript(控制器)之间的绑定部分。它起着将控制器加入视图的作用。它对于视图和控制器均可用。


如何使用范围

要在AngularJS中创建控制器,你必须将$ scope对象作为参数传递。

请参阅以下示例:

<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<h1>{{carname}}</h1>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
    $scope.carname = "Volvo";
});
</script>
<p>The property "carname" was made in the controller, and can be referred to in the view by using the {{ }} brackets.</p>
</body>
</html>
赞(0)
未经允许不得转载:srcmini » angularjs范围

评论 抢沙发

评论前必须登录!