The example in this article describes a workaround for the conflict between the template view and the Angularjs. Share to everyone for your reference, specific as follows:
Problem:
In the MVC view of PHP, we need to be in the process of loading
Pass some data to the template:
Such as:
This is some controller.
$data [' users '] = {something from databases};
$this->load->view (' Home/index ', $data);
Here is the corresponding view
<div ng-controller= "LoadData" >
<ul>
<!--1. When initializing, we need to use the following sentence-->
<?php foreach ( Users as user):?>
<li><?= $user->name?>:<?= $user->email?><li>
<?php Endforeach?>
<!--2. But after the end we need to use this to update-->
<li ng-repeat= "user in Users" >{{user.name} through Ajax: {{user.email}}</li>
</ul>
</div>
So now the question is, how do you deal with the contradiction between 1 and 2?
First Solution:
<script>
var usersprefetch = [
<?php foreach (users as user):?>
{"name": "<?= $user->name ?> "," email ":" <?= $user->email?> "},
<?php endforeach?>
];
</script>
We store the data from PHP in a variable and then pass
$scope to assign it, OK
Second solution (recommended):
We use the Ng-if property to solve our problem by invoking PHP data when the user is undefined
Use our data and define $scope when the Ajax pass is complete. Users
<ul ng-if= "!users" >
<?php foreach (users as user):?> <li><?=
$user->name?>:< ? = $user->email?><li>
<?php endforeach?>
</ul>
<ul ng-if= "Users" >
<li ng-repeat= "user in Users" >{{user.name}}:{{user.email}}</li>
</ul>
Demo Demo Address: https://jsfiddle.net/mser49aq/1/
I hope this article will help you to Angularjs program design.