2017-02-07 7 views
0

angular js zeigt nichts auch nur wie einfache Ausdrücke. Ich bin verpflichtet, unter Code auszuführen, aber keine Hoffnung. Kann mir jemand helfen?Angular Js funktioniert nicht richtig

unter Code ist für die Anzeige angezeigt.

`<html> 
 
<head> 
 
    <title></title> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script> 
 
    <script type="text/javascript" src="/../../Scripts/angularsample.js"></script> 
 
</head> 
 
<body ng-app="spiceApp"> 
 
    <div> 
 
     <div ng-controller="SpicyController"> 
 
      <p> lets try some code by using service </p> 
 
      <input ng-init="message='Girish'" ng-model="message" /> 
 
      <button ng-click="notify(message);">Notify{{1+2}}</button> 
 
      <p>alert will display only by clicking three times.</p> 
 
     </div> 
 
     <div ng-controller="List"> 
 
      <button ng-click="bringList()">getList</button> 
 
      <table> 
 
       <tr ng-repeat="app in appslist"> 
 
        <td> 
 
         {{app.Name}} 
 
        </td> 
 
       </tr> 
 
      </table> 
 
      </div> 
 
    </div> 
 
</body> 
 
</html>`

js Code

var myApp = angular.module('spiceApp', []); 
 

 
myApp.controller('SpicyController', ['$scope', '$http', 'userService', , function ($scope, $http, userService) { 
 

 
    //below code is using sservice 
 
    $scope.notify = function (msg) { 
 
     userService(msg); 
 
    }; 
 
    
 
}]); 
 

 

 
myApp.controller('List', ['$scope', 'getList', function ($scope, getList) { 
 
    $scope.bringList = function() { 
 
     getList.getAppsList().then(function (list) { 
 
      $scope.appslist = list; 
 
     }); 
 
    }; 
 

 
}]); 
 

 
myApp.factory('getList', ['$http',function ($http) { 
 
    //this code for getting list from controller. 
 
    return getList.getAppsList=function(){ 
 
     $http({ 
 
      method: 'GET', 
 
      url: 'Home/GetAppsList' 
 
     }) 
 
    .success(function (response) { 
 
     return response.data; 
 
    }, function (error) { 
 
     console.log(error); 
 
    }); 
 
    } 
 
}]); 
 

 
myApp.factory('userService', ['$window', function (win) { 
 
    var msgs = []; 
 
    return function (msg) { 
 
     msgs.push(msg); 
 
     if (msgs.length == 3) { 
 
      win.alert(msgs.join('\n')); 
 
      msgs = []; 
 
     } 
 
    }; 
 

 
}]);`

Bitte sagen Sie mir, wo ich falsch bin. nichts funktioniert. Ausdruck wird wie {{1 + 2}} in der Ausgabe angezeigt.

+0

Haben Sie Fehler in der Konsole? – Alteyss

+0

jetzt bekomme ich Fehler in der Konsole ist: –

+0

ReferenceError: getList ist nicht definiert bei Object. (angularsample.js: 36) bei Object.invoke. (Angularjs: 4708) bei Objekt erhält $ (Angularjs: 4547) bei Object.invoke (Angularjs: 4708) bei Angularjs : 4507 bei d (Angularjs: 4654) bei e (Angularjs: 4678) bei Object.invoke (Angularjs: 4700) bei P.instance (Angularjs: 10177) bei n (angular.js: 9096) (anonym) @ angular.js: 13642 –

Antwort

1

Sie haben einen Tippfehler hier:

myApp.controller('SpicyController', ['$scope', '$http', 'userService', , function 

mit dem 2 comas so die Abhängigkeiten sind vermasselt.

+0

Ja, jetzt funktioniert die Vorlage einwandfrei. aber nicht in der Lage, die Liste von Service zu Controller –

+0

zurückgeben können Sie bitte einen Blick darauf –

0

ich versuchte auf andere Weise mit der gleichen Ansicht, aber ich modifizierte die Js-Datei jetzt funktioniert es gut.

var myApp = angular.module('spiceApp', []); 
 

 
myApp.controller('SpicyController', ['$scope', '$http', 'userService',function ($scope, $http, userService) { 
 

 
    //below code is using sservice 
 
    $scope.notify = function (msg) { 
 
     userService(msg); 
 
    }; 
 
    
 
}]); 
 

 
myApp.factory('userService', ['$window', function (win) { 
 
    var msgs = []; 
 
    return function (msg) { 
 
     msgs.push(msg); 
 
     if (msgs.length == 3) { 
 
      win.alert(msgs.join('\n')); 
 
      msgs = []; 
 
     } 
 
    }; 
 

 
}]); 
 

 

 
myApp.controller('List', ['$scope', 'getList', function ($scope, getList) { 
 
    
 
    $scope.bringList = function() { 
 
     getList.getAppsList.then(function (data) { 
 
      $scope.appslist = data; 
 
     }); 
 

 
    }; 
 

 
}]); 
 

 
var getList = angular.module("spiceApp").factory("getList", ['$http', function ($http, getList) { 
 
    return { 
 
     getAppsList: (function (response) { 
 

 
      return $http({ 
 
       method: 'GET', 
 
       url: 'GetAppsList' 
 
      }) 
 
      .then(function (response) { 
 
       console.log("coming from servicejs", response.data); 
 
       //return data when promise resolved 
 
       //that would help you to continue promise chain. 
 
       return response.data; 
 
      }); 
 
     })() 
 
    }; 
 
    return getList; 
 
}]);

Verwandte Themen