由网友(胡思滥想)分享简介:我在根文件夹命名为控制器的控制器。我认为我要附加到当对应的视图的路由变化。我采用了棱角分明的UI路由器。I have a controller in a folder named controller at the root.I have view that I want to attach to the corr...
我在根文件夹命名为控制器的控制器。我认为我要附加到当对应的视图的路由变化。我采用了棱角分明的UI路由器。
I have a controller in a folder named controller at the root. I have view that I want to attach to the corresponding views when the route changes. I am using angular-ui-router.
控制器/ one.js
controllers/one.js
angular.module('sub',["ui.router"]).config(function($stateProvider){
$stateProvider
.state('index', {
url: "/login",
views: {
"viewA": {
templateUrl: "login.html"
}
}
})
.state('register', {
url: "/register",
views: {
"viewA": {
templateUrl: "register.html"
}
}
})
.state('upload', {
url: "/upload",
views: {
"viewA": {
templateUrl: "upload.html"
}
}
})
})
的test.html
test.html
<!DOCTYPE html>
<html ng-app="sub">
<head>
<title>AngularJS: UI-Router Quick Start</title>
<!-- Bootstrap CSS -->
<link href="bootstrap.min.css" rel="stylesheet">
</head>
<body class="container">
<div class="navbar">
<div class="navbar-inner">
<a class="brand" ui-sref="index">Quick Start</a>
<ul class="nav">
<li><a ui-sref="index">Home</a></li>
<li><a ui-sref="register">Register</a></li>
<li><a ui-sref="upload">upload</a></li>
</ul>
</div>
</div>
<div class="row">
<div class="span6">
<div class="well" ui-view="viewA"></div>
</div>
</div>
<script type="text/javascript" src="angular.min.js"></script>
<script type="text/javascript" src="Controllers/one.js"></script>
<script type="text/javascript" src="angular-cookies.js"></script>
<script type="text/javascript" src="Controllers/loginController.js"></script>
<script type="text/javascript" src="Controllers/uploadController.js"></script>
<script type="text/javascript" src="Controllers/registerController.js"></script>
<script type="text/javascript" src="angular-ui-router.js"></script>
<script type="text/javascript" src="jquery-2.1.3.min.js"></script>
</body>
</html>
的login.html
login.html
<div ng-controller="loginController">
<p>
UserName:
<input id="director" type="text" ng-model="mUserName"/>
</p>
<p>
Password:
<input id="actor" type="text" ng-model="mPassWord"/>
</p>
<button ng-click="login()">Login</button>
</div>
控制器/ LoginController.js
Controllers/LoginController.js
angular.module('subsd',["ngCookies"]).controller('loginController', ['$http','$scope','$cookies',function($http,$scope,$cookies) {})]);
如果我提到的,而不是在loginController.js路由停止工作subsd'子'。
If I mention 'sub' instead of 'subsd' in loginController.js the routing stops working.
推荐答案
最终的答案,包括几件事情要做:
The final answer includes few things to do:
删除&LT; DIV NG控制器=的LoginController方式&gt;
从的login.html 的模板文件将在'ngCookies
依赖于分
模块中的控制器/ one.js 的文件( angular.module('子',[ui.router,ngCookies])
)。在控制器/ logincontroller.js 的文件更改从 subsd
模块名称为分
回来,并从子第二个参数
模块调用,以使它看起来像这样: angular.module(子)。控制器(...)
。
Remove <div ng-controller="loginController">
from the login.html template file.
Move the 'ngCookies'
dependency to the sub
module definition in controllers/one.js file (angular.module('sub',["ui.router", "ngCookies"])
).
In the controllers/logincontroller.js file change the module name from subsd
to sub
back again and remove the second argument from the sub
module invoke, to make it look like this: angular.module('sub').controller(...)
.
当你改变之前的模块名称,您试图重新定义它,这是错误的。
When you changed the module name before, you were trying to re-define it, which is an error.
这
angular.module('moduleName', [...dependencies])
是模块的二传手,而这个
angular.module('moduleName')
是模块的的getter
相关推荐
最新文章