Skip to content

Instantly share code, notes, and snippets.

@shinofara
Created May 23, 2013 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shinofara/5637372 to your computer and use it in GitHub Desktop.
Save shinofara/5637372 to your computer and use it in GitHub Desktop.
【メモ】【AngularJSのススメ】URLに応じて部分的に更新を行う方法(ルーティング)に関して ref: http://qiita.com/items/3f904e73a6eb1f929acd
when("/hoge", {
when("/hoge/:id", {
angular.module("app", []).
<div ng-app="app">
<a href="http://xxxxx/hoge/123">有効リンク</a>
<div ng-view></div>
<a href="http://xxxxx/hoge/1234567">有効リンク</a>
</div>
<a href="http://xxxxx/hoge/123">無効リンク</a>
<!-- 相対パスをbaseで指定した場所から始める -->
<base href="/hoge/" />
when("/", {
when("/:id", {
$locationProvider.html5Mode(true);
<html ng-app="app">
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular-resource.min.js"></script>
<script>
angular.module("app", []).
config(["$routeProvider", '$locationProvider', function($routeProvider,$locationProvider) {
//$locationProvider.hashPrefix('!');
$locationProvider.html5Mode(true);
$routeProvider.
when("", {
// テンプレート文字列を指定
templateUrl: '/template/teacher/index.html',
// テンプレートにバインドするコントロールの名前を指定
controller: MainCtrl
}).
when("/:id", { //任意の文字列の場合
         /* 省略 */
})
.otherwise({redirectTo: '/'});
}]);
</script>
</head>
<body>
<div ng-view>ここにテンプレートが挿入されるよ。</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment