无法添加第二个ng-controller

Gleb Z.

我在angular / js开发中还很新,所以现在我把它叠了起来。

当我在我的HTML代码中添加ng-controller =“ HeaderController”时,它无法加载Angular。如果删除此选项,一切都很好。为什么会这样呢?感谢您的帮助,对于英语不好,谢谢您:)

代码:

(function() {
	var app = angular.module ('FunStuff',[]);

	app.controller ('TextController',['$scope',function($scope){
		$scope.stuff = [];
		$scope.add = function(){
				$scope.stuff.push ($scope.name);
		}
	}]);
	app.controller ('HeaderController'['$scope',function($scope){
		$scope.textClass = '';
		$scope.changeClrClss = function(name){
			$scope.ClrClss = name;
		}
	}]);
})();
<!DOCTYPE html>
<html ng-app ="FunStuff">

<head>
	<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.min.js"></script>
	<link rel="stylesheet" type="text/css" href="style.css">
	<title>LEARN JS</title>
	<meta charset="utf-8">
</head>

<body >

	<header  ng-class = "ColorClass" ng-controller="HeaderController">
		<h1>$~/Path_To_Js/</h1>
		<button class="changeColorBtn" ng-click="changeColorClass('white')">
			ChangeColorButton
		</button>
	</header>

	<div class="wrapper" >
		<article ng-controller = "TextController">
			<p>There will be some information</p>
			<form ng-submit="add()">
				<input ng-model="name"><button>Add</button>
			</form>
			<ul class="buttons" ng-repeat= "n in stuff track by $index">
				<li>{{n}}</li>
			</ul>
		</article>
	</div>
	<script type="text/javascript" src="index.js"></script>
</body>

</html>

萨耶塔兰(Sajeetharan)

正如您的错误所言:,标头控制器之后,您不见了

app.controller ('HeaderController',['$scope',function($scope){
        $scope.textClass = '';
        $scope.changeClrClss = function(name){
            $scope.ClrClss = name;
        }
    }]);

演示

var app = angular.module ('FunStuff',[]);

	app.controller ('TextController',['$scope',function($scope){
		$scope.stuff = [];
		$scope.add = function(){
				$scope.stuff.push ($scope.name);
		}
	}]);
	app.controller ('HeaderController',['$scope',function($scope){
		$scope.textClass = '';
		$scope.changeClrClss = function(name){
			$scope.ClrClss = name;
		}
	}]);
<!DOCTYPE html>
<html ng-app ="FunStuff">

<head>
	<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.min.js"></script>
	<link rel="stylesheet" type="text/css" href="style.css">
	<title>LEARN JS</title>
	<meta charset="utf-8">
</head>

<body >

	<header  ng-class = "ColorClass" ng-controller="HeaderController">
		<h1>$~/Path_To_Js/</h1>
		<button class="changeColorBtn" ng-click="changeColorClass('white')">
			ChangeColorButton
		</button>
	</header>

	<div class="wrapper" >
		<article ng-controller = "TextController">
			<p>There will be some information</p>
			<form ng-submit="add()">
				<input ng-model="name"><button>Add</button>
			</form>
			<ul class="buttons" ng-repeat= "n in stuff track by $index">
				<li>{{n}}</li>
			</ul>
		</article>
	</div>
	<script type="text/javascript" src="index.js"></script>
</body>

</html>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

可以将第二个参数传递给Controller构造函数吗?

来自分类Dev

可以将第二个参数传递给Controller构造函数吗?

来自分类Dev

尝试注释MapView并同时加载第二个View Controller

来自分类Dev

window.location.href上的第二个参数在Controller上为NULL

来自分类Dev

添加项目以建模并刷新第二个ng-repeat

来自分类Dev

ng-if不隐藏第二个元素

来自分类Dev

动态添加第二个Google Map后无法正确呈现

来自分类Dev

无法在我的表单中添加第二个下拉列表

来自分类Dev

无法在第二个图像后添加jQuery的东西

来自分类Dev

JavaScript:无法将第二个值添加到单链表

来自分类Dev

无法向Spring Data Starter项目添加第二个实体

来自分类Dev

动态添加第二个Google Map后无法正确呈现

来自分类Dev

添加第二个菜单时,我无法单击菜单上的元素

来自分类Dev

无法在回收站视图中添加第二个孩子

来自分类Dev

无法循环并为数组添加第二个值

来自分类Dev

向当前查询添加第二个SUM

来自分类Dev

从第二个查询SQL添加列

来自分类Dev

添加第二个RSU时交换消息

来自分类Dev

向lapply函数添加第二个参数

来自分类Dev

在R中添加第二个y轴

来自分类Dev

在第二个Swift上添加rightBarButtonItem

来自分类Dev

Python添加第二个时间对象

来自分类Dev

向ggplot添加第二个y轴

来自分类Dev

Django添加第二个静态文件URL

来自分类Dev

添加第二个查询以存在ajax调用

来自分类Dev

向Angular模块添加第二个服务

来自分类Dev

XML-如何添加第二个条目?

来自分类Dev

添加第二个日期选择器,

来自分类Dev

如何添加第二个硬盘?