2015-01-05 2 views
-2

Я новичок в angularjs, помогите.Как позвонить в службы по обслуживанию angularjs

Как получить услуги обслуживания java для моего кода. Я использую данные mockup json.

var orderVariable = angular.module('ordermodule',[]); 

orderVariable.controller('formController',['$scope', '$state', function($scope, $state) { 

    $scope.processForm = function() { 
     alert('awesome!'); 
    }; 

    $scope.formData = {}; 

}]); 

/////////////////////////////////////////// ////////////

orderVariable.factory('orderableItemsService', function() { 

    var orderableItemsService = { 

    products:[{"name":"ACUVUE OASIS with HYDRACLEAR 6 Pack","description":{"description":"Acuvue Advance Plus contact lenses give your eyes what they need all day longsuperior comfort and moisture. Your eyes will retain the smooth sensation of a new pair of contacts thanks in large part to HYDRACLEAR technology, which builds moisture into the lens itself. Each time you blink, the built-in moisture acts as a natural lubricant for your eye. It's a refreshingly comfortable experience in a bi-weekly lens. This is the Acuvue Advance Plus 24 pack of contacts. You can also purchase this lens in a 6 pack.","details":"Details:1>LENS TYPE: 1-2 week soft disposable contact lenses.2>PACKAGE DETAILS: 24 lenses in buffered saline with methyl ehter cellulose.3>MATERIAL AND % OF CONTENT: 53% galyfilcon A.4>WATER % OF CONTENT: 47%.5>MANUFACTURER: Johnson and Johnson Vision Products, Inc., Jacksonville, FL", 
     "eyeType":"LeftOD","power":"-3.21","bc":"4","dia":"11.2","boxes":[1,2,3,4],"lensType":"1-2 week soft disposable contact lenses."}, 
     "quantity":4,"itemid":"1","shippingaddress":"Library 1400 Chicago Ave Albany NY 12222","upc":124,"unitcost":160}, 
     {"name":"ACUVUE OASIS with HYDRACLEAR 6 Pack","description":{"description":"Acuvue Advance Plus contact lenses give your eyes what they need all day longsuperior comfort and moisture. Your eyes will retain the smooth sensation of a new pair of contacts thanks in large part to HYDRACLEAR technology, which builds moisture into the lens itself. Each time you blink, the built-in moisture acts as a natural lubricant for your eye. It's a refreshingly comfortable experience in a bi-weekly lens. This is the Acuvue Advance Plus 24 pack of contacts. You can also purchase this lens in a 6 pack.","details":"Details:1>LENS TYPE: 1-2 week soft disposable contact lenses.2>PACKAGE DETAILS: 24 lenses in buffered saline with methyl ehter cellulose.3>MATERIAL AND % OF CONTENT: 53% galyfilcon A.4>WATER % OF CONTENT: 47%.5>MANUFACTURER: Johnson and Johnson Vision Products, Inc., Jacksonville, FL", 
      "eyeType":"RightOD","power":"-1.11","bc":"2","dia":"13.2","boxes":[1,2,3,4],"lensType":"1-2 week soft disposable contact lenses."},"quantity":4,"itemid":"2","shippingaddress":"Library 1400 Chicago Ave Albany NY 12222","upc":124,"unitcost":160}, 
      {"name":"ACUVUE LENS SOLUTION","description":{"description":"Acuvue Advance Contact Lens Solution.........","details":"","eyeType":"","power":"","bc":"","dia":"","boxes":[1,2,3,4],"lensType":"Contact Lens Solution........."},"quantity":null,"itemid":"3","shippingaddress":null,"upc":null,"unitcost":null}], 
    checks: [], 
    checkr: [] 
    }; 
    return orderableItemsService; 
}); 

orderVariable.controller('prodCtrl1', function($scope,$http,orderableItemsService) { 

    $scope.boxVal=0; 
    $scope.formData = orderableItemsService; 
    $scope.itemList=[]; 
}); 


orderVariable.controller('prodCtrl2', function($scope, orderableItemsService) { 

    $scope.formData = orderableItemsService; 
}); 
+2

Не могли бы вы прояснить этот вопрос? –

ответ

1

Вы можете использовать Spring для этого.

Основном вы можете сделать следующее:

Создать весенний проект и создать файл (пример Greeting.java)

package hello; 

public class Greeting { 

    private final long id; 
    private final String content; 

    public Greeting(long id, String content) { 
     this.id = id; 
     this.content = content; 
    } 

    public long getId() { 
     return id; 
    } 

    public String getContent() { 
     return content; 
    } 
} 

Используйте @RestController, чтобы получить данные, которые нужно

package hello; 

import java.util.concurrent.atomic.AtomicLong; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestParam; 
import org.springframework.web.bind.annotation.RestController; 

@RestController 
public class GreetingController { 

    private static final String template = "Hello, %s!"; 
    private final AtomicLong counter = new AtomicLong(); 

    @RequestMapping("/greeting") 
    public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) { 
     return new Greeting(counter.incrementAndGet(), 
          String.format(template, name)); 
    } 
} 

и запустить приложение с

package hello; 

import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 
import org.springframework.boot.SpringApplication; 
import org.springframework.context.annotation.ComponentScan; 

@ComponentScan 
@EnableAutoConfiguration 
public class Application { 

    public static void main(String[] args) { 
     SpringApplication.run(Application.class, args); 
    } 
} 

нагель получить дату в своем угловом контроллере, как следует:

function Hello($scope, $http) { 
    $http.get('http://rest-service.guides.spring.io/greeting'). 
     success(function(data) { 
      $scope.greeting = data; 
     }); 
} 

Где заменить rest-service.guides.spring.io с правильным адресом и так.

для получения дополнительной информации смотрите пожалуйста here и here

+0

Добро пожаловать в [so]! По возможности, пожалуйста, не отправляйте ответы, которые просто указывают на другую веб-страницу. Если источник полезен, укажите соответствующие его части в своем ответе или, еще лучше, перепишите его своими словами (вы все равно можете ссылаться на него, конечно). Для получения дополнительной информации см. [Ответ]. Благодаря! –

+0

@ Qantas94Heavy это лучше? – joey

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