Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Conclusions: For <strong>problem #2</strong>. There a two types of JSON.</p> <p>a)<strong>JSONObject</strong> like this single row:</p> <pre><code>{ 'id':'123', 'title':'my house' } </code></pre> <p>b)<strong>JSONArray</strong> like this single row:</p> <pre><code>[ { 'id':'123', 'title':'my house' } ] </code></pre> <p>Do you see the brackets? Or like this other JSONArray:</p> <pre><code>[ { 'id':'123', 'title':'my house' }, { 'id':'124', 'title':'my car' } ] </code></pre> <p>With JSONObjects, you must use {{post.title}} in the template.</p> <pre><code>&lt;div&gt; {{post.title}} &lt;/div&gt; </code></pre> <p>{{post[0].title}} shall give you an error because data isn't an array. It doesn't use brackets.</p> <p>And with JSONArrays (with one or more rows), you can use ng-repeat in the template, like:</p> <pre><code>&lt;div ng-repeat="post in post"&gt; {{post.title}} &lt;/div&gt; </code></pre> <p>Or, also you can access directly a specific row:</p> <pre><code>&lt;div&gt; {{post[0].title}} &lt;br&gt; {{post[1].title}} &lt;/div&gt; </code></pre> <hr> <p>For <strong>problem #1</strong>, you could use something like explained here:</p> <p><a href="http://docs.angularjs.org/tutorial/step_11" rel="nofollow">Step #11 in AngularJS' tutorial ($resource)</a></p> <p>But, I found easier to do a single change; this is my previous code:</p> <pre><code>function postCtrl($scope, $http, $routeParams) { $http.get('post.php?id=' + $routeParams.postId).success(function(data) { $scope.post = data; }); $scope.description = $scope.post.meta_description; /*I can't access this value*/ } </code></pre> <p>The problem is $scope.post only exists inside the function inside $http.get; it's like a private variable that can't be access from outside of the function.</p> <p>So an easier solution than to use $resource, was to move $scope.description inside $http.get.</p> <pre><code>function postCtrl($scope, $http, $routeParams) { $http.get('post.php?id=' + $routeParams.postId).success(function(data) { $scope.post = data; $scope.description = data.meta_description; }); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload