저는 최근에 AngularJS를 배우려고했지만 제가 만든 각도 모듈을 보려면 HTML을 볼 수 없습니다.HTML에 AngularJS 모듈 포함
<!DOCTYPE html>
<html ng-app="productsModule">
<head>
\t <meta charset="UTF-8">
\t
\t <script src="../lib/dependencies/angular.min.js"></script>
\t <script src="../lib/dependencies/angular-resource.min.js"></script>
\t
\t <script src="../scripts/products.module.js"></script>
\t
\t <title>ProductsTestPage</title>
</head>
<body>
\t <div ng-contoller="ProductListJSController as productList">
\t \t <h1>Product Test Page</h1>
\t \t
\t \t <span>Total number of products: {{ productList.total() }}</span>
\t \t
\t \t <span>{{ productList.test }}</span>
\t
\t \t <table>
\t \t \t <thead>
\t \t \t \t <tr>
\t \t \t \t \t <th>ID</th>
\t \t \t \t \t <th>Name</th>
\t \t \t \t \t <th>Price (£)</th>
\t \t \t \t </tr>
\t \t \t </thead>
\t \t \t <tbody>
\t \t \t \t <tr ng-repeat="product in productList.products">
\t \t \t \t \t <td>{{product.id}}</td>
\t \t \t \t \t <td>{{product.name}}</td>
\t \t \t \t \t <td>{{product.price}}</td>
\t \t \t \t </tr>
\t \t \t </tbody>
\t \t </table>
\t
\t \t <p> 1 + 2 = {{1+2}} </p>
\t </div>
\t
</body>
</html>
내 JS :
angular.module('productsModule', [])
\t .controller('ProductListJSController', function(){
\t \t //var productList = this;
\t \t
\t this.test = 'test';
\t \t
\t this.products = [
\t \t {id: 53, name:'gnome 1', price: 50},
\t \t {id: 54, name:'gnome 2', price: 70},
\t \t {id: 55, name:'gnome 3', price: 90}];
\t this.total = function(){
\t \t var count = 0;
\t \t angular.forEach(this.products, function(){
\t \t \t count += 1;
\t \t });
\t \t return count;
\t };
});
내 HTML을 보인다
나는 모든 것을 올바르게했음을 확신한다. 그리고 발견 한 예제와 거의 같지만 제품 모듈을 참조하는 바인딩을 표시하지 않는 것 같다.
괜찮 았나? 컨트롤러가 DOM에 적용되지 않았습니까? 또는 어떤 오류가 발생하고 있습니까? –
전혀 오류가 발생하지 않습니다. 페이지가 표시되고 모든 정적 HTML이 정상적으로 나타납니다. {{1 + 2}} 표현조차도 작동합니다. 하지만 JS 파일의 실제 내용 (예 : {{productList.test}})을 참조하는 항목은 전혀 표시되지 않습니다. –
'{{...}}'표현식이 잘 작동하면 컨트롤러가 DOM을 사용하고 있음을 의미합니다. 이제'productList.test' 객체를 콘솔에 체크인하십시오. 거기에 어떤 항목이 있건 없건간에 ... –