angularjs - ng-include not working for basic angular 1 code -


ok, there're many similar questions, went through , me more confused, btw started learning angular 1 2 weeks ago.

  1. in browser, /mypath/status.html works fine, sends "testjson" node server, displays data webpage

  2. now have /mypath/index2.html, ng-include status.html, won't trigger "testjson" in server code

status.html

<!doctype html> <html ng-app="hellomodule">   <head>       <meta content="text/html;charset=utf-8" http-equiv="content-type">   </head>    <body  ng-controller="helloctrl">     <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.6/ angular.js"></script>     <script src="statusapp.js"></script>       <table>       <tr>         <th>code</th>         <th>country</th>         <th>population</th>       </tr>         <tr ng-repeat="country in countries | orderby: 'code' ">         <th>{{country.code}}</th>         <th>{{country.name}}</th>         <th>{{country.population}}</th>       </tr>     </table>    </body>  </html> 

statusapp.js

var app = angular.module('hellomodule', []);  app.controller('helloctrl', function($scope, helloservice) {         //$scope.countries = [{code : "us", name : "united states", population : "11223344"}];      helloservice.getjson().then(function(result) {         $scope.countries = result;     }, function(error) {         alert("error");     } ); });   app.factory('helloservice', function($http, $q) {    return {      getjson:  function() {         var deferred = $q.defer();          var browserprotocol = 'http';         var port = ':1234';         var address = 'localhost';         var server = browserprotocol + '://' + address;         var url = server + port + '/testjson';          //$http.get('http://localhost:7778/testjson').success(function(data) {         $http.get(url).success(function(data) {             deferred.resolve(data);         }).error(function(){             deferred.reject();         });         return deferred.promise;     }   } }); 

index2.html not working, don't see line console.log("returning json data"); triggered in server

<!doctype html> <html ng-app>    <head>        <meta content="text/html;charset=utf-8" http-equiv="content-type">    </head> <body>  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.6/angular. min.js"></script>  <div class="container">     <div ng-include="" src="'status.html'"></div> </div>  </body> </html> 

server side

app.get('/testjson', function(req, res) {         console.log("returning json data");     res.json( [{code : "us", name : "united states", population : "11223344" }] ); }); 

the status.html want include :

  <table ng-controller="helloctrl" >       <tr>         <th>code</th>         <th>country</th>         <th>population</th>       </tr>         <tr ng-repeat="country in countries | orderby: 'code' ">         <th>{{country.code}}</th>         <th>{{country.name}}</th>         <th>{{country.population}}</th>       </tr>     </table> 

right ?

edit

and ng-include works :

<div class="container">     <div ng-include="'status.html'" ></div> </div> 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -