带颜色的简单角度js示例 [英] Simple angular js example with colors
问题描述
我正在按照教程
Tryit Editor v3.1 [ ^ ]
我已将$ rootscope更改为第一个控制器的范围。但现在它不会列出颜色。
应该是:
蓝色
红色
红色,我做了更改后。
<!DOCTYPE html>
< html>
< script src =https://ajax.googleapis.com/ajax/libs/angularjs/1.4。 8 / angular.min.js>< / script>
< body ng-app =myApp>
< p> rootScope最喜欢的颜色:< / p>
< h1> {{color}}< / h1>
< div ng-controller =myCtrl>
< p>控制器最喜欢的颜色范围:< / p>
< h1> {{color}}< / h1>
< / div>
< p> Scope最喜欢的颜色是:< / p>
< h1> {{color}}< / h1>
< script>
var app = a ngular.module('myApp',[]);
app.run(函数($ scope){
$ scope.color ='blue';
});
app.controller('myCtrl',函数($ scope){
$ scope.color =red;
});
< / script>
< p>请注意,控制器的颜色变量不会覆盖rootScope的颜色值。< / p>
< / body>
< / html>
我的尝试:
------------- ----------- ************ ************************************************** ************************************************** ******************************************
I am following the tutorial
Tryit Editor v3.1[^]
I have changed $rootscope to scope for the first controller . but now it wont list the colors.
Should it be:
Blue
Red
Red , after i made the changes.
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body ng-app="myApp">
<p>The rootScope's favorite color:</p>
<h1>{{color}}</h1>
<div ng-controller="myCtrl">
<p>The scope of the controller's favorite color:</p>
<h1>{{color}}</h1>
</div>
<p>The Scope's favorite color is :</p>
<h1>{{color}}</h1>
<script>
var app = angular.module('myApp', []);
app.run(function($scope) {
$scope.color = 'blue';
});
app.controller('myCtrl', function($scope) {
$scope.color = "red";
});
</script>
<p>Notice that controller's color variable does not overwrite the rootScope's color value.</p>
</body>
</html>
What I have tried:
------------------------*************************************************************************************************************************************************************************************
推荐答案
rootscope作为第一个控制器的范围。但现在它不会列出颜色。
应该是:
蓝色
红色
红色,我做了更改后。
<!DOCTYPE html>
< html>
< script src =https://ajax.googleapis.com/ajax/libs/angularjs/1.4。 8 / angular.min.js>< / script>
< body ng-app =myApp>
< p> rootScope最喜欢的颜色:< / p>
< h1> {{color}}< / h1>
< div ng-controller =myCtrl>
< p>控制器最喜欢的颜色范围:< / p>
< h1> {{color}}< / h1>
< / div>
< p> Scope最喜欢的颜色是:< / p>
< h1> {{color}}< / h1>
< script>
var app = a ngular.module('myApp',[]);
app.run(function(
rootscope to scope for the first controller . but now it wont list the colors.
Should it be:
Blue
Red
Red , after i made the changes.
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body ng-app="myApp">
<p>The rootScope's favorite color:</p>
<h1>{{color}}</h1>
<div ng-controller="myCtrl">
<p>The scope of the controller's favorite color:</p>
<h1>{{color}}</h1>
</div>
<p>The Scope's favorite color is :</p>
<h1>{{color}}</h1>
<script>
var app = angular.module('myApp', []);
app.run(function(
scope){
scope) {
scope.color ='blue';
});
app.controller('myCtrl',function(
scope.color = 'blue';
});
app.controller('myCtrl', function(
)
这篇关于带颜色的简单角度js示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!