Q
Q
qwertyuih2017-03-05 21:22:59
Angular
qwertyuih, 2017-03-05 21:22:59

How to fix template rendering in angular?

I'm going through the angular tutorial, I've done the distribution over various files (controllers separately, templates separately, etc.). When connected, nothing is displayed, absolutely. Here is the code from index.php client:

<!DOCTYPE html>
<html>
<head>
<title>Angular</title>
<script src="angular-js/angular.js"></script>
<script src="test.js"></script>
<script src="controllers.js"></script>
</head>
<body ng-app='NewAppModule'>
<div ng-view></div>
</body>
</html>

Code with test.js module:
angular.module('NewAppModule', []);
angular.module('NewAppModule', []).
  component('div', {
          templateUrl: 'template.html',
          controller: 'ContactView'       <----Проблема возникает при подключении контроллера в этом месте.
});

and the template itself:
<p>
Поиск: <input type='text' ng-model='search' placeholder='Поиск..'>
</p>
<p>
Сортировка: <select ng-model='sort'>
          <option value='name'>По имени</option>
       <option value='number'>По номеру</option>
</select>
</p>
<ul>
         <li ng-repeat="people in $ctrl.contact | filter: search | orderBy: sort" style="list-style: none">
            <p>Имя: <a href="/contacts/{{people.name}}">{{people.name}}</a></p>
           <p>Телефон: {{people.number}}</p>
          <hr>
         </li>
      </ul>

And controller: controllers.js
var ctrl=angular.module('NewAppModule', []);
ctrl.controller('ContactView',['$http', function($http){
var self=this;
var url='/app.json';
 $http({url: url, method:'GET'}).then(function(response) {
       self.contact=response.data;
      });
}]);

If the controller is declared in the module itself, where I indicated, then everything appears well. But if I call it from a separate file (in my case, controllers.js), for some reason the call fails + even the template is not displayed. It seems that he did everything according to the tutorial. What is the jamb?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
emp1re, 2017-03-05
@emp1re

index. php
Didn't read further

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question