dongqiang1226 2016-01-23 01:45
浏览 58

如何将数据从视图中获取到离子中的另一个视图?

I have followed this tutorial ionic/angular - get data from database - data loaded, but no output on site on how to retrieve data from database and show it in ionic but the problem is the data can only be seen in one view and I dont know how to view it in another view

screencap - I have successfully display the recipes in my ionic from my database and when I click the pen icon it should be displaying the recipe name, ingredients and more

screencap 2 - but when I click it it doesnt show any data.

here's my code for viewing data :

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 (ionic)

.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 (ionic)

 getRecipeService.all().then(function(payload) {
 $scope.userrecipedata = payload.data;
 console.log(payload);
});

profile.html ( ionic )

 <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 ( ionic - in this html I want to display the data here also but it shows no data in the input type. What should I do?)

    <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>
  • 写回答

1条回答 默认 最新

  • dqmchw0071 2016-01-23 06:56
    关注

    Use http for controller

    .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;
    }); 
    })
    
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP