Problem:
In the MVC view of PHP, we need to be in the process of loading
Pass some data to the template:
Such as:
Here is a 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 phrase via AJAX update-- <li ng-repeat= "user in Users" >{{ User.name}}:{{user.email}}</li> </ul></div>
So now the question is how to deal with the contradiction between 1 and 2?
The first of these solutions:
<script> var usersprefetch = [ <?php foreach (users as user):?> {"name": "<?= $user->name ?> "," email ":" <?= $user->email?> "}, <?php endforeach?> ];</script>
We store the data passed by PHP in a variable and then
$scope assign a value to it, OK
Second solution (recommended):
We use the Ng-if property to solve our problem and call PHP data when users are 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 Address: https://jsfiddle.net/mser49aq/1/
Angularjs Learning Four (resolving conflicts between template views and Angularjs)