【发布时间】:2014-05-25 03:13:29
【问题描述】:
我有角度路线工作,但我被困在我不确定是否可能的特定部分。我想使用外部控制器文件。
工作代码示例:
app.config(function($locationProvider, $routeProvider) {
$locationProvider.html5Mode(true);
$routeProvider
.when('/', {
templateUrl: '/AngularViews/Home/index.html'
}).when('/Login', {
templateUrl: 'AngularViews/Account/index.html',
controller: 'registerUser'
}).otherwise({ redirectTo: '/'});
});
app.controller('registerUser', function($scope) {
$scope.hello = 'test';
})
我想做的更像是这样:
app.config(function($locationProvider, $routeProvider) {
$locationProvider.html5Mode(true);
$routeProvider
.when('/', {
templateUrl: '/AngularViews/Home/index.html'
}).when('/Login', {
templateUrl: 'AngularViews/Account/index.html',
}).otherwise({ redirectTo: '/'});
});
用于模板登录的 HTML:
<script src="../../AngularScripts/Account/account.js"></script>
REGISTRATION
<div ng-controller="registerUser">
{{hello}}
</div>
Account.js 文件:
app.controller('registerUser', function($scope, data) {
$scope.hello = 'hello';
$scope.registerUser = function () {
var createData = {
"UserName": $scope.email,
"Password": $scope.password,
"ConfirmPassword": $scope.confirmpass
};
console.log(createData);
return createData;
};
})
第二种方式时,它一直告诉我 registerUser 是未定义的,因为它找不到 registerUser
【问题讨论】:
-
我相信那些其他帖子并不是我想要的。如果他们是我正在寻找的,他们还不够清楚
标签: angularjs