本文概述
- 如何使用范围
如何使用范围要在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>
推荐阅读
- angularjs依赖注入
- angularjs模块
- angularjs控制器
- angularjs指令
- angularjs数据绑定
- angularjs表达式
- angularjs第一个app
- angularjs mvc体系结构
- 什么是angularjs