2
Currently I have an array in php that I convert to JSON using json_encode
json and generated smoothly.
$array = array('a' => 'Olá mundo', 'b' => 'Olá Marte');
$array = json_encode(array);
//$array agora retorna {"a":"Olá mundo","b":"Olá Marte"} .
I’m using angular ui router to change my pages dynamically, usually when you want to send parameters via ui-router we use
<a href="#" ui-sref="ver({parametro:valor})"> clique aqui </a>
works normally and can valor
without a JSON object made javascript.
Now as I try to do
<a href="#" ui-sref="ver({parametro:"<?php echo json_encode($array) ?>"})"> clique aqui </a>
The console returns me the following error
Error: Invalid state ref 'view({video:{' D@http://localhost/arte/js/angular-ui-router/release/angular-ui-router.min.js:7:25266 I/<.link@http://localhost/arte/js/angular-ui-router/release/angular-ui-router.min.js:7:26135 ab/<@http://localhost/arte/js/angular/angular.min.js:16:69 ta@http://localhost/arte/js/angular/angular.min.js:84:35 n@http://localhost/arte/js/angular/angular.min.js:69:226 g@http://localhost/arte/js/angular/angular.min.js:60:496 g@http://localhost/arte/js/angular/angular.min.js:61:12 g@http://localhost/arte/js/angular/angular.min.js:61:12 g@http://localhost/arte/js/angular/angular.min.js:61:12 ba/<@http://localhost/arte/js/angular/angular.min.js:60:119 B/<.compile/<@http://localhost/arte/js/angular-ui-router/release/angular-ui-router.min.js:7:24965 ab/<@http://localhost/arte/js/angular/angular.min.js:16:69 ta@http://localhost/arte/js/angular/angular.min.js:84:35 n@http://localhost/arte/js/angular/angular.min.js:69:226 g@http://localhost/arte/js/angular/angular.min.js:60:496 ba/<@http://localhost/arte/js/angular/angular.min.js:60:119 gc/<@http://localhost/arte/js/angular/angular.min.js:65:279 l@http://localhost/arte/js/angular-ui-router/release/angular-ui-router.min.js:7:23877 A/l.compile/</<@http://localhost/arte/js/angular-ui-router/release/angular-ui-router.min.js:7:24297 If/this.$get</m.prototype.$broadcast@http://localhost/arte/js/angular/angular.min.js:150:426 w/z.transitionTo/z.transition<@http://localhost/arte/js/angular-ui-router/release/angular-ui-router.min.js:7:19286 h/<@http://localhost/arte/js/angular/angular.min.js:134:167 If/this.$get</m.prototype.$eval@http://localhost/arte/js/angular/angular.min.js:148:43 If/this.$get</m.prototype.$digest@http://localhost/arte/js/angular/angular.min.js:145:83 If/this.$get</m.prototype.$apply@http://localhost/arte/js/angular/angular.min.js:148:339 l@http://localhost/arte/js/angular/angular.min.js:101:87 sg/</t.onload@http://localhost/arte/js/angular/angular.min.js:106:489 <a href="#" ui-sref="view({video:{" titulo":"a","urlvideo":"htt","duracao":"2:2","datapub":"2017-02-15","views":"100","descricao":"white","palavraschave":"ley"}})"="">
Error: Invalid state ref
if I’m not mistaken when php hera json it puts double quotes"
, And the quotes of the attribute are also double, so I guess when you find the first quote of the json, you kind of close the quote of the attribute, and the json is invalid. just to make sure theui-sref="ver({parametro:"<?php echo json_encode($array) ?>"})">
thereforeui-sref='ver({parametro:"<?php echo json_encode($array) ?>"})'>
. Note that attributionui-sref
this with single quotes'
– Neuber Oliveira
@Neuberoliveira following his example I needed to just take out the double quotes getting
ui-sref='ver({parametro:<?php echo json_encode($array) ?>})'>
recognized normal JSON, ates for some reason json was returning with a="
in the end, but now it’s worked.– joao paulo santos almeida
I didn’t realize you had quotation marks on
parametro
^^– Neuber Oliveira