700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 详解AngularJS中的作用域_AngularJS

详解AngularJS中的作用域_AngularJS

时间:2022-01-17 13:38:37

相关推荐

详解AngularJS中的作用域_AngularJS

web前端|js教程

AngularJS

web前端-js教程

范围扮演其视图连接控制器的角色一个特殊的JavaScript对象。范围包含了模型数据。在控制器,模型数据通过$scope对象访问。

h5微信大转盘抽奖源码,UBUNTU下载壁纸高级,tomcat6的用途,蜘蛛爬虫特征,大专生面试php,seo 手机lzw

var mainApp = angular.module("mainApp", []); mainApp.controller("shapeController", function($scope) {$scope.message = "In shape controller";$scope.type = "Shape"; });

以下是在上面的例子中需要考虑的重要问题。

php. 财务系统源码,ubuntu启动网站教程,做爬虫的方法,网站php组件,南宁seo猴王lzw

$scope被作为第一个参数在其构造器确定指标到控制器。

$scope.message 和 $scope.type 是它们在HTML页面中所用的模型。

我们已经设置模型的值将反映应用程序模块的控制器shapeController中。

我们可以在$scope定义函数功能。

dedecms网址导航源码,vscode 如何退出全屏,ubuntu 效率工具,tomcat高并发数,sqlite怎么设置数据库,诗词名句网是不是有反爬虫,刷信誉源码php,对seo有害的是,篮球网站模板,bootstrap框架的模板下载lzw

继承范围

范围是特定的控制器。如果我们定义嵌套的控制器,然后控制器子将继承其父控制的范围。

var mainApp = angular.module("mainApp", []); mainApp.controller("shapeController", function($scope) {$scope.message = "In shape controller";$scope.type = "Shape"; });mainApp.controller("circleController", function($scope) {$scope.message = "In circle controller";});

以下是在上面的例子中需要考虑的重要问题。

我们在shapeController设定模型的值。

我们覆盖的子控制器circleController消息。当“消息”内的控制器circleController的模块使用时,将用于重写的消息。

例子

下面的例子将展示上述所有指令。

testAngularJS.html

Angular JS FormsAngularJS Sample Application

{{message}}

{{type}}

{{message}}

{{type}}

{{message}}

{{type}}

var mainApp = angular.module("mainApp", []); mainApp.controller("shapeController", function($scope) {$scope.message = "In shape controller";$scope.type = "Shape"; }); mainApp.controller("circleController", function($scope) {$scope.message = "In circle controller";}); mainApp.controller("squareController", function($scope) {$scope.message = "In square controller";$scope.type = "Square"; });

结果

在Web浏览器打开textAngularJS.html。看到结果如下。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。