cancel
Showing results for 
Search instead for 
Did you mean: 

Magento2 AngularJs cocktail

Magento2 AngularJs cocktail

Hello

I have a problem when i try to made interact some data from AngularJs with my template I need a little correction on my code please i'm stuck again.

 

So in my controller i'm saying that : 

'descReplaces' => $blockInstance->getAll()

 

In my block i'm saying that getAll() :

foreach ($newData as $d )  {
	        $tabl[] = array(
		        'toreplace' => $d->getToreplace(),
		        'replaceby' => $d->getReplaceby()
	        );
	    }

And it work i tested it and gave me :

Array ( [0] => Array ( [toreplace] => TEXTE A REMPLACER [replaceby] => TEXTE REMPLACANT ) [1] => Array ( [toreplace] => test1 [replaceby] => test2 ) )

 

but finally when i call it in my template with Angular it don't give me the array.

 

 

Here is the full code :

my controller 

<?php
      namespace Mymodule\AdminPage\Controller\Adminhtml\AdminDescsdev;

      class Index extends \Magento\Backend\App\Action
      {
        protected $resultPageFactory;

        public function __construct(
            \Magento\Backend\App\Action\Context $context,
            \Magento\Framework\View\Result\PageFactory $resultPageFactory
        ) {
             parent::__construct($context);
             $this->resultPageFactory = $resultPageFactory;
        }
	    
	    public function ajaxProcessGetDescReplaces()
	    {
			$blockInstance = $this->_objectManager->get('Mymodule\AdminPage\Block\Adminhtml\Contactslist');
	        die(json_encode(array(
	            'descReplaces' => $blockInstance->getAll()
	        )));
	    }
	    
        public function execute()
		{
		    return  $resultPage = $this->resultPageFactory->create();
        }
    }
?>

 

my block :

<?php
namespace Mymodule\AdminPage\Block\Adminhtml; use Magento\Backend\Block\Template; class Contactslist extends \Magento\Backend\Block\Template { public function __construct( \Magento\Backend\Block\Template\Context $context, \Mymodule\AdminPage\Model\ContactFactory $contactFactory, \Magento\Framework\View\Result\PageFactory $resultPageFactory, array $data = [] ) { parent::__construct($context, $data); $this->contactFactory = $contactFactory; $this->resultPageFactory = $resultPageFactory; } public $definition = array( 'table' => 'mytable', 'primary' => 'Id', 'multilang' => false, 'fields' => array( 'toreplace' => array('type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, 'validate' => 'isGenericName', 'required' => true, 'size' => '255'), 'replaceby' => array('type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, 'validate' => 'isGenericName', 'required' => true, 'size' => '255') ) ); public function getAll(){ $data = array(); $model = $this->contactFactory->create(); $newData = $model->getCollection(); $tabl = array(); foreach ($newData as $d ) { $tabl[] = array( 'toreplace' => $d->getToreplace(), 'replaceby' => $d->getReplaceby() ); } return $tabl; } }

 

my template :

 

<tr ng-repeat="(keyDescReplace,descReplace) in descReplaces">
<td>{{ descReplace.toreplace }}</td>
<td>{{ descReplace.replaceby }}</td>
<td>
<button ng-click="editDescReplace(descReplace.id)" class="button btn btn-warning">
Modifier
</button>
<button ng-click="deleteDescReplaces(descReplace.id)" class="button btn btn-danger">
Supprimer
</button>
</td>
</tr>