0

ниже мой угловой JS файл .html и я доступ с помощью http://localhost:3000/modulename/create проблемы является angularjs не работает, как, например, нг повтор пуст в шаблоне-ки, тогда, когда мы утешать объект в JavaScript это возвращаемые значения см выделенный раздел на скриншоте ниже для справочных целейAngularjs не работает в nodejs выразить

enter image description here

угловые app.js

angular.module('scotchTodo', ['todoController']); 


angular.module('todoController', []) 

    // inject the Todo service factory into our controller 


    .controller('ContactController', ['$scope','$http', function($scope, $http, Todos) { 


     $scope.contacts = [ 
     {id:0, 'name': 'PremAseem', 'email':'[email protected]', 'phone': '123-2343-44'} 
    ]; 
    console.log($scope.contacts) 


    }]); 

угловой HTML код

<!-- ASSIGN OUR ANGULAR MODULE --> 
<html ng-app="scotchTodo"> 
<head> 
    <!-- META --> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"><!-- Optimize mobile viewport --> 

    <title>Node/Angular Todo App</title> 

    <!-- SCROLLS --> 
    <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css"><!-- load bootstrap --> 
    <link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css"> 
    <style> 
    html   { overflow-y:scroll; } 
    body   { padding-top:50px; } 
    #todo-list  { margin-bottom:30px; } 
    #todo-form  { margin-bottom:50px; } 
    </style> 

    <!-- SPELLS --> 
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.min.js"></script><!-- load angular --> 


    <script src="../../admin/js/app.js"></script> <!--load up our controller --> 

</head> 
<!-- SET THE CONTROLLER --> 
<body > 
<div ng-controller="ContactController"> 
    <form class="well"> 
    <label>Name</label> 
     <input type="text" name="name" ng-model="newcontact.name"/> 
    <label>Email</label> 
     <input type="text" name="email" ng-model="newcontact.email"/> 
    <label>Phone</label> 
     <input type="text" name="phone" ng-model="newcontact.phone"/> 
     <br/> 
     <input type="hidden" ng-model="newcontact.id" /> 
    <input type="button" value="Save" ng-click="saveContact()" class="btn btn-primary"/> 
    </form> 
<table class="table table-striped table-bordered"> 
<thead> 
<tr> 
    <th>Name</th> 
    <th>Email</th> 
    <th>Phone</th> 
    <th>Action</th> 
</tr> 
</thead> 
<tbody> 
<tr ng-repeat="contact in contacts"> 
    <td>{{ contact.name }}</td> 
    <td>{{ contact.email }}</td> 
    <td>{{ contact.phone }}</td> 
    <td> 
     <a href="#" ng-click="edit(contact.id)">edit</a> | 
     <a href="#" ng-click="delete(contact.id)">delete</a> 
    </td> 
</tr> 
</tbody> 
</table>  
</div> 






</body> 
</html> 
+0

Что происходит, когда вы берете на 'mainController' в теге тела? – TheLazyChap

+1

все еще проблема сохраняется –

+0

ваш код показывает, что вы никогда не объявляли ContactController в модуле приложения. Похоже, что это просто нормальная функция. – TheLazyChap

ответ

3

Проблема была с консолидации шаблонов. Спасибо @nirmal за выпуск вычетов. Решение заключалось в том, чтобы изменить шаблоны.

app.js:

var app = angular.module('scotch', [], function($interpolateProvider) { 
    $interpolateProvider.startSymbol('[{'); 
    $interpolateProvider.endSymbol('}]'); 
}) 
0

Попробуйте

angular.module('scotchTodo', ['todoController']); 


angular.module('todoController', []) 

    // inject the Todo service factory into our controller 


    .controller('ContactController', ['$scope','$http', function($scope, $http, Todos) { 
     scope.contacts = []; 
     var data = {id:0, 'name': 'PremAseem', 'email':'[email protected]', 'phone': '123-2343-44'}; 
     $scope.contacts.push(data); 
    console.log($scope.contacts) 


    }]); 
+1

проблема сохраняется и есть исправление выше сообщения scope.contacts знак равно должен быть $ scope.contacts = []; right –

1


Проблема из-за вашего вида двигателя, используемого в nodejs/выразить https://www.npmjs.com/package/consolidate
В основном большинство на стороне сервера/клиента вид сбоку двигателей использовал шаблон {{data}} для шаблонов, в вашем коде ваши привязки урезаны вашим механизмом просмотра.
Html Ответ вашего/api-вызова, предоставляющего HTML-фрагменты без вашего фактического связывания, внесенного вами в ваш код.

(1) 
    If you move you modulename.html, app.js inside public folder and if you access the same through node server. It works as expected. 
    You can try this. 
    Compare the response HTML snippets for below two cases from Browser Network Tab, 
     1. /api 
     2. /modulename.html // after placing modulename.html in public folder 
(2) 
    For any problem in Javascript frameworks, browser console is our best friend. You can navigate to console and access scope object of element you can get the "contacts" object. 
    Or you can bind you contacts object model to any text box using ng-model, or ng-bind directives. 
    you can get your contacts value in html. 

(3) 
    If you want to still use view engine in server side, even though you have master piece angular in browser. You can choose ng-bind directive for you angularjs template. 
    It's always better approach to use ng-bind directive in our templates, instead of {{}} pattern. 

Hope this helps you on the issue. Please feel free to ping me, if not resolved. 

enter image description here

+1

мы можем что-то реализовать на линиях http://stackoverflow.com/questions/29614183/angularjs-interpolate-provider-not-working –

Смежные вопросы