【发布时间】:2015-07-10 10:38:31
【问题描述】:
谁能帮帮我,我不知道我做错了什么。我正在关注平均网络开发教程。 ng-include 适用于模板,但 ng-view 不适用。我有 5 个文件。首先是Users.client.module.js:
angular.module('users', []);
其次是 users.client.controller.js
angular.module('users',['ngRoute']).controller('UsersController', ['$scope',
function ($scope){
$scope.name = 'UsersCont';
console.log("from UsersCont");
}]);
第三个是 users.client.routes.js
angular.module('users').config(['$routeProvider', function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'users/views/register-user.client.view.html'
})
.otherwise({
templateUrl: '/somewhere else'
});
}]);
第四个是register-client-view.html
<section ng-controller="UsersController">
<h1>{{ name }}</h1>
</section>
最后是 index.html
<section ng-include=" 'users/views/register-user.client.view.html' "></section>
<section ng-view> </section>
<script type="text/javascript" src="/users/users.client.module.js"></script>
<script type="text/javascript" src="/users/controllers/users.client.controller.js"></script>
请帮忙
【问题讨论】:
-
我在 index.html 中的任何地方都看不到
ng-app它是引导 ng 应用程序所必需的。这看起来也很奇怪ng-include=" 'users/views/register-user.client.view.html' "- 为什么你里面有额外的引号? -
我有文件用于手动引导 application.js var mainApplicationModuleName = 'myApp'; var mainApplicationModule = angular.module(mainApplicationModuleName, ['ngResource' ,'ngRoute', 'users', 'articles']); mainApplicationModule.config(['$locationProvider', function ($locationProvider){ $locationProvider.hashPrefix('!'); }]); angular.element(document).ready(function(){ angular.bootstrap(document, [mainApplicationModuleName]); }); ng-include 工作正常,我尝试不使用单引号但不工作。我认为问题出在路线的某个地方,但我找不到它。也尝试使用 ng-app
-
我没有看到您在索引中加载
users.client.routes.js。你有这个吗? -
omg..谢谢你 1000 次 Devin H. 我没有包含 users.client.rotues.js...
标签: angularjs routes mean-stack