我已按照本教程ionic/angular - get data from database - data loaded, but no output on site 关于如何从数据库中检索数据并以离子形式显示它,但问题是数据只能在一个视图中看到,我不知道如何在另一个视图中查看它
screencap - 我已经成功地从我的数据库中显示我的离子配方,当我点击笔图标时,它应该显示食谱名称,成分和更多
screencap 2 - 但是当我点击它时,它不会显示任何数据。
这是我查看数据的代码:
user_model.php(codeigniter - model)
public function user_recipe_data()
{
$this->db->select('*');
$this->db->from('usersrecipes');
$this->db->join('user', 'user.user_id = usersrecipes.user_id');
$this->db->where('usersrecipes.user_id = 12 ');
$query = $this->db->get();
return $query->result_array();
}
Main.php(codeigniter - controller)
public function get_user_recipe_data()
{
$postdata = json_decode(file_get_contents("php://input"));
$user_recipe = $this->User_model->user_recipe_data();
echo json_encode($user_recipe);
}
RecipeService.js(离子)
.factory('getRecipeService',function($ http){
return {
all: function() {
return $http.get("http://localhost/admin-recipick/api/Main/get_user_recipe_data");
},
get: function(Recipe_ID) {
q = $http.get("http://localhost/admin-recipick/api/Main/get_user_recipe_data");
for (var i = 0; i < q.length; i++) {
if (q[i].id === parseInt(Recipe_ID)) {
return q[i];
}
}
return null;
}
};
});
controller.js(离子)
getRecipeService.all().then(function(payload) {
$scope.userrecipedata = payload.data;
console.log(payload);
});
profile.html(离子)
<ion-list>
<ion-item ng-repeat="recipe in userrecipedata" class="item-remove-animate item-avatar item-icon-right" type="item-textu-wrap" href="#/app/recipes/{{recipe.Recipe_ID}}">
<img ng-src="img/food/porkmenudo.jpg">
<h2>{{recipe.Recipename}}</h2>
<p>{{recipe.Ingredients}}</p>
<i class="icon ion-edit"></i>
<ion-option-button class="button-assertive" ng-click="remove(recipe)">
Delete
</ion-option-button>
</ion-item>
</ion-list>
recipe-detail.html(离子 - 在这个html中我想在这里显示数据,但它在输入类型中没有显示数据。我该怎么办?)
<div class="list">
<label class="item item-input">
<span class="input-label">Index Name</span>
<input type="text" ng-model="recipe.Recipe_ID">
</label>
<label class="item item-input">
<span class="input-label">Recipe Name</span>
<input type="text" ng-model="recipe.Recipename">
</label>
<label class="item item-input">
<span class="input-label">Ingredients</span>
<input type="text" ng-model="recipe.Ingredients">
</label>
<label class="item item-input item-select">
<span class="input-label">Cooking Time</span>
<select ng-model="recipe.Cookingtime">
<option value="20mins">20mins</option>
<option value="30mins">30mins</option>
<option value="1hr">1hr</option>
</select>
</label>
<label class="item item-input">
<textarea placeholder="PROCEDURE" rows="12" ng-model="recipe.Procedure">
</textarea>
</label>
<button class="button button-block button-assertive h1" ng-click="AddRecipe()">Update Recipe</button>
</div>
答案 0 :(得分:0)
使用http作为控制器
.controller('Ctrl', function($scope, $http, $stateParams) {
$scope.userrecipedata = [];
$http.get('http://localhost/admin-recipick/api/Main/get_user_recipe_data').success(function(response){
$scope.userrecipedata = response;
});
})