angularjs - Using angular factory in separate typescript file -


i define factory in 1 file (movie.ts), this:

(function () { 'use strict';  angular     .module('moviesservices', ['ngresource'])     .factory('movie', movie);  movie.$inject = ['$resource'];  function movie($resource) {     return $resource('/api/movies/:id'); } })(); 

then try use in file (moviescontroller.ts), note typescript:

function moviesaddcontroller($scope, $location, movie) {     $scope.movie = new movie();     $scope.add = function () {         $scope.movie.$save(function () {             $location.path('/');         });     }; } 

typescript complains on "new movie();" error message "cannot resolve symbol 'movie'."

how can define movie factory? tried exporting movie class don't know how convert factory typescript class.

this works in javascript , example taken this tutorial.

well, i'm still learning typescript , don't know if helps solved above problem first rewriting factory service, such:

export class webapiservice {     static $inject = ["$resource"];     constructor(private $resource: ng.resource.iresourceservice)     {     }      public movies()     {         return this.$resource("/api/movies/:id");     } } app.service("webapiservice", webapiservice); 

then, in controller, used code:

var movie = webapiservice.movies(); $scope.movie = new movie(); 

a simplified example of using $resource create new entity be:

var movie = $resource("/api/movies/:id"); $scope.movie = new movie(); 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

Kivy: Swiping (Carousel & ScreenManager) -

jdbc - Not able to establish database connection in eclipse -