Skip to content

Commit

Permalink
list.htmlを外部ファイルにし、AngularJSが動いてから表示することで、AngularJS適用前のDOMが表示されることを防止 #6
Browse files Browse the repository at this point in the history
  • Loading branch information
sinmetal committed May 19, 2013
1 parent 39e0a27 commit dc846a9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 25 deletions.
4 changes: 4 additions & 0 deletions app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ handlers:
static_files: index.html
upload: index.html

- url: /list.html
static_files: list.html
upload: list.html

- url: /lib
static_dir: lib

Expand Down
21 changes: 1 addition & 20 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,7 @@
<body>
<div ng-controller="MainController">
<h2>Hello AngularJS !!</h2>
<div>
<table class="table">
<thead>
<tr>
<td>No</td>
<td>CategoryId</td>
<td>ItemId</td>
<td>Name</td>
</tr>
</thead>
<tbody ng-repeat="s in stores">
<tr>
<td>{{$index}}</td>
<td>{{s.CategoryId}}</td>
<td>{{s.ItemId}}</td>
<td>{{s.Name}}</td>
</tr>
</tbody>
</table>
</div>
<div ng-view></div>
<div>
<form ng-submit="submit()">
<select ng-model="entryForm.categoryId" ng-options="c.id as c.name for c in categories" ng-change="changeCategory()">
Expand Down
18 changes: 13 additions & 5 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
(function() {
var app = angular.module("sample", ["ngResource"]);
app.controller("MainController", function($scope, $resource){
$scope.categories = [{"id" : "1", "name" : "野菜"}];
var List = $resource("/item/list");
var Store = $resource("/store");
var app = angular.module('sample', ['ngResource']).
config(function($routeProvider) {
$routeProvider.
when('/', {controller:ListController, templateUrl:'list.html'});
});

function ListController($scope, $resource) {
var Store = $resource("/store");
$scope.stores = Store.query(function() {
console.log("success store query");
console.log($scope.stores);
console.log($scope.stores[0].CategoryId);
}, function(){
console.log("error store query");
});
}

app.controller("MainController", function($scope, $resource){
$scope.categories = [{"id" : "1", "name" : "野菜"}];
var List = $resource("/item/list");
var Store = $resource("/store");

$scope.changeCategory = function() {
$scope.items = List.query({id : $scope.entryForm.categoryid}, function(){
Expand Down
20 changes: 20 additions & 0 deletions list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<div>
<table class="table">
<thead>
<tr>
<td>No</td>
<td>CategoryId</td>
<td>ItemId</td>
<td>Name</td>
</tr>
</thead>
<tbody ng-repeat="s in stores">
<tr>
<td>{{$index}}</td>
<td>{{s.CategoryId}}</td>
<td>{{s.ItemId}}</td>
<td>{{s.Name}}</td>
</tr>
</tbody>
</table>
</div>

0 comments on commit dc846a9

Please sign in to comment.