我在Ruby on Rails中使用AngularJS進行應用程序。 我的application.js文件UI-view not changed
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require angular.min
//= require angular-ui-router.min
var app = angular.module("railsApp", ['ui.router']).config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('home', {
url: '/',
templateUrl: 'home.html'
})
.state('about', {
url: 'about',
templateUrl: 'about.html'
});
$urlRouterProvider.otherwise('/');
});
app.controller("mainCtrl", function($scope) {
$scope.helloMsg = "Hello from test application";
});
索引頁
<h1>Welcome#index</h1>
<p>Find me in app/views/welcome/index.html.erb</p>
{{helloMsg}}<br>
<ui-view></ui-view>
<a ui-sref="about">about</a>
當索引頁面加載我看到消息「你好,從測試應用程序」,進入<ui-view></ui-view>
取代模板的內容,但我點擊有關鏈接新模板未加載並且url未更改爲/ about。問題是什麼?感謝和抱歉我的英文
唉唉......按秒打我:) – sameera207
非常感謝你,你的建議有助於糾正問題! – motoroller
正確的配置是'var app = angular.module(「railsApp」,['ui.router']).config($ stateProvider $ urlRouterProvider){stateProvider .state('home',{ url : '/', templateUrl: 'home.html做爲' }) .STATE( '約',{ URL: '/約', templateUrl: 'about.html' }); $ urlRouterProvider.otherwise ('/'); }); app.controller(「mainCtrl」,function($ scope){ $ scope.helloMsg =「Hello from test application」; });' – motoroller