【发布时间】:2017-10-20 12:44:42
【问题描述】:
那里!我正在尝试使用部分,但不工作:
我的 html 文件已创建并就位,我不明白为什么它不起作用!
我正在使用 angular 1.6.4 和 ui-router 1.0.0-rc.1
谁能帮帮我?
myApp.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/home');
$stateProvider
.state("home", {
url: "/home",
templateUrl: "home.html",
controller: "HomeController",
});
$stateProvider
.state("about", {
url: "/about",
templateUrl: "about.html",
controller: "AboutController",
});
$stateProvider
.state("contact", {
url: "/contact",
templateUrl: "contact.html",
controller: "ContactController",
});
});
myApp.controller('HomeController', function($scope, $location) {
$scope.message = 'Home Controller!';
});
myApp.controller('AboutController', function($scope) {
$scope.message = 'About Controller.';
});
myApp.controller('ContactController', function($scope) {
$scope.message = 'Contact Controller';
});
如果我更改为 this(如下),它就可以正常工作:
var myApp = angular.module('helloworld', ['ui.router']);
myApp.config(function($stateProvider) {
var helloState = {
name: 'hello',
url: '/hello',
template: '<h3>hello world!</h3>'
}
var aboutState = {
name: 'about',
url: '/about',
template: '<h3>Its the UI-Router hello world app!</h3>'
}
$stateProvider.state(helloState);
$stateProvider.state(aboutState);
});
【问题讨论】:
标签: html angularjs angular-ui-router partials