有人可以帮助我,我不知道我做错了什么。我遵循平均网络开发教程。 Ng-include可以与模板一起工作,但不能使用ng-view。我有5个文件。首先是Users.client.module.js:ng view is not working but ng include working in angularjs
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'
});
}]);
四is register-client-view.html
<section ng-controller="UsersController">
<h1>{{ name }}</h1>
</section>
and last is ind ex.html
<section ng-include=" 'users/views/register-user.client.view.html' "></section>
<section ng-view> </section>
<script type="text/javascript" src="https://stackoverflow.com/users/users.client.module.js"></script>
<script type="text/javascript" src="https://stackoverflow.com/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){ \t $ locationProvider.hashPrefix('!'); }]); (document,[mainApplicationModuleName]); }); ng-include工作正常,我试过没有单引号,但没有工作。我认为问题是与路线的某处,但我无法找到它。也尝试与ng-app – userDC
我没有看到你加载'users.client.routes.js'在你的索引。你有这个吗? –