小编Pra*_*A.K的帖子

Angular2可观察的份额不起作用

Angular2 Observable共享无效并且重复http调用

BuildingService.ts

@Injectable()
export class BuildingService {

constructor(private http: Http){       
  }

buildings$: Observable<Building[]>;
this.buildings: Building[];

getData() : Observable<Building[]>{
     this.buildings$ = this.http.get('http://localhost:8080/buildings').share().map(this.extractData);
     this.buildings$.subscribe(buildings => this.buildings = buildings);
     return this.buildings$;
  }

 private extractData(res: Response) {
    let body = res.json();
    return body;
} 

}
Run Code Online (Sandbox Code Playgroud)

component1.ts

export class component1 {
constructor( private  buildingService: BuildingService) {}

this.subscription = this.buildingService.getData()
            .subscribe(buildings => console.log(buildings),
            error =>  this.errorMessage = <any>error);
}
Run Code Online (Sandbox Code Playgroud)

component2.ts

export class component2 {
constructor( private  buildingService: BuildingService) {}

this.subscription = this.buildingService.getData()
            .subscribe(buildings => console.log(buildings), …
Run Code Online (Sandbox Code Playgroud)

observable rxjs angular2-services rxjs5 angular

5
推荐指数
1
解决办法
5013
查看次数

Angular2检查对象是否在*ngIf内有peoperty

export interface Element {    
    name: string;   
}

export class Room implements Element {
name: string; 
type:string
}

export class Hall implements Element {
name: string;
}
Run Code Online (Sandbox Code Playgroud)

我的varibale类型如下所示

selectedElement: Element;
Run Code Online (Sandbox Code Playgroud)

现在在HTML中我如何检查对象是否具有属性'类型'?

<div *ngIf="selectedElement?.type">
my div
</div>
Run Code Online (Sandbox Code Playgroud)

typescript angular-ng-if angular2-components angular

4
推荐指数
3
解决办法
1万
查看次数

用https固定测试弹簧支架控制器

任何人都可以为我提供一个代码示例来为使用HTTPS保护的控制器编写集成测试吗?使用HTTP我能够写,但使用HTTPS我得到认证错误.

调节器

@RestController
@RequestMapping("/rest/otm/v1")
public class LoginController {  

    @Autowired
    UserAuthenticationService userAuthService;

    @ExceptionHandler({ AuthenticationFailedException.class})
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    @ResponseBody
    public void login(HttpServletRequest request,HttpServletResponse response) throws AuthenticationDeniedException {

        //some code
    }

}
Run Code Online (Sandbox Code Playgroud)

测试类

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebAppConfiguration
@IntegrationTest("server.port:0") 
public class IdentityControllerTest {

    @Value("${local.server.port}")
    int port;

    @Test
    public void test_Login_Controller() {

        SimpleClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory();

        Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("some-proxy", 8080));
        clientHttpRequestFactory.setProxy(proxy);

        RestTemplate restTemplate = new RestTemplate(clientHttpRequestFactory);

        HttpHeaders requestHeaders = new HttpHeaders();
        requestHeaders.set("credential", "pratap");
        requestHeaders.set("deviceid", "xyz123");

        HttpHeaders …
Run Code Online (Sandbox Code Playgroud)

spring-test spring-test-mvc spring-boot spring-restcontroller

3
推荐指数
1
解决办法
6146
查看次数

AngularJS $过滤器在控制器中具有相同属性的条件或条件

控制器:

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

myApp.controller('myCtrl', ['$scope', '$filter', function($scope, $filter){

    $scope.tickets = [
                      {title : 'ticket1', assignee : {id:'pratap', name: 'PRATAP'}},
                      {title : 'ticket2', assignee : null},
                      {title : 'ticket3', assignee : {id:'ak', name: 'AK'}}
                      ];    

    $scope.defaultOption = 1;
    $scope.options = [
                      {id:1, name : 'MY TICKETS'},
                      {id:2, name : 'OTHERS TICKET'}
                      ];

    $scope.filteredTicket = [];

    $scope.filterData = function(criteria) {
        if (criteria == 1) {
            $scope.filteredTicket = $filter('filter')($scope.tickets, {assignee: {id:'pratap'}});
        } else {
            $scope.filteredTicket = $filter('filter')($scope.tickets, {assignee: null, assignee: …
Run Code Online (Sandbox Code Playgroud)

angularjs angularjs-filter

3
推荐指数
1
解决办法
8755
查看次数

如何在高图表点击事件中调用打字稿功能

MyHighChartComponent.ts

export class MyHighChartComponent {
    highchartsConfiguration: any = {
        chart: {
            events: {
                click(e) {
                    if (!($(event.target)[0].textContent)) {
                        console.log('clicked'); //this is printing
                        this.drillDown(); // how to call typescript function here?
                    }
                },
            },
        }
    };  

    drillDown() {
      console.log('drill down method called');
    }
}
Run Code Online (Sandbox Code Playgroud)

如何从高图表点击事件内部调用打字稿函数?

我得到以下错误

错误堆栈:TypeError:this.drillDown 不是函数

charts this highcharts typescript angular

3
推荐指数
1
解决办法
2373
查看次数

如何在Spring Boot项目中忽略特定URL的Spring Security CSRF

如何忽略特定URL的CSRF安全性,例如“ / workflow / **”。除了该URL,我还需要所有URL和方法的授权和CSRF安全。

@Configuration
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
protected static class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Autowired
    private RESTAuthenticationEntryPoint authenticationEntryPoint;

    @Autowired
    private RESTAuthenticationFailureHandler authenticationFailureHandler;

    @Autowired
    private RESTAuthenticationSuccessHandler authenticationSuccessHandler;

    @Autowired
    private PranaUserDetailsService userDetailsService;

    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http.csrf().requireCsrfProtectionMatcher(new AllExceptUrlStartedWith("/workflow"))          
        .and().authorizeRequests()
        .antMatchers("/rest/**", "/tasklist").authenticated()
        .and().logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
        .logoutSuccessUrl("/index.html")        
        .and().exceptionHandling().authenticationEntryPoint(authenticationEntryPoint)
        .and().formLogin().successHandler(authenticationSuccessHandler)
        .and().formLogin().failureHandler(authenticationFailureHandler)         
        .and().csrf().csrfTokenRepository(csrfTokenRepository()).and().addFilterAfter(new CsrfHeaderFilter(), CsrfFilter.class);
    }

    private static class AllExceptUrlStartedWith implements RequestMatcher {

        private static final String[] ALLOWED_METHODS =
                new String[] {"GET"};

        private final String[] allowedUrls;

        public AllExceptUrlStartedWith(String... allowedUrls) {
            this.allowedUrls = allowedUrls; …
Run Code Online (Sandbox Code Playgroud)

java csrf spring-security rest-client spring-boot

2
推荐指数
1
解决办法
2223
查看次数

java jackson如果对象类型的变量序列化后保留类型信息

A级

public class ClassA {
   private String id;
   private Object rawData;
}
Run Code Online (Sandbox Code Playgroud)

B级

public class ClassB {
   private String name;
}
Run Code Online (Sandbox Code Playgroud)

C类

public class ClassC {
   String address;
}
Run Code Online (Sandbox Code Playgroud)

主班

public class MainExample {
   public static void main( String[] args ) throws IOException {

      ObjectMapper mapper = new ObjectMapper(  );

      ClassB classB = new ClassB();
      //ClassC classC = new ClassC();
      ClassA classA = new ClassA();
      classA.setRawData(  classB );
      //classA.setRawData(  classC );

      if (classA.getRawData() instanceof ClassB) {
         System.out.println("true ");
      } else …
Run Code Online (Sandbox Code Playgroud)

java serialization jackson deserialization objectmapper

2
推荐指数
1
解决办法
8759
查看次数

AngularJS ng-if具有角度表达式

视图:

<html ng-app="myApp">
....
  <body>

    <div ng-controller="myCtrl">

      <p>Current user {{loggedOnUser}}</p>

      <div ng-if="user.name == {{loggedOnUser}}" ng-repeat="user in users">
        <p>Should display</p>
      </div>

    </div>

  </body>

</html>
Run Code Online (Sandbox Code Playgroud)

控制器:

angular.module("myApp", [])
  .controller("myCtrl", function($scope){
    $scope.loggedOnUser = "xxx"; // for testing purpose
    $scope.users = [
      {
        name : "xxx",
        age: "25"
      },
      {
        name : "yyy",
        age: "26"
      }
    ];
 });
Run Code Online (Sandbox Code Playgroud)

如何使用ng-if与angularJS表达式或有任何其他方法来实现这一点?如果我的loggedOnUser等于user.name,我想显示div

提前致谢

angularjs angularjs-scope angularjs-ng-repeat angular-ng-if

1
推荐指数
1
解决办法
1万
查看次数

如何从rest客户端调用Spring STOMP Web套接字方法

我的Java代码用URL/hello拦截所有调用(返回):

@Controller
public class GreetingController {

    @MessageMapping("/hello")
    @SendTo("/topic/greetings")
    public Greeting greeting(HelloMessage message) throws Exception {
        Thread.sleep(3000); // simulated delay
        return new Greeting("Hello, " + message.getName() + "!");       
    }    
}
Run Code Online (Sandbox Code Playgroud)

我的JavaScript代码调用方法greeting()(Front):

function sendName() {
    var name = document.getElementById('name').value;
    stompClient.send("/app/hello", {}, JSON.stringify({ 'name': name }));
}
Run Code Online (Sandbox Code Playgroud)

有人可以告诉我如何从Rest客户端调用@MessageMapping("/ hello")方法.我可以通过JavaScript代码连接,甚至可以获得响应并以HTML格式显示它.但我有一个要求,外部系统(通过休息调用)应该调用此@MessageMapping("/ hello"),然后应用程序(后端)应该发送对HTML的响应.我试图从chrome rest客户端插件调用@MessageMapping("/ hello")方法,但是没有成功.

请让我知道如何调用此方法?提前致谢

spring stomp rest-client sockjs spring-websocket

1
推荐指数
1
解决办法
4789
查看次数

Angular2单个ng用于多个数组

是否可以在Angular中使用多个数组用于ngFor?

   *ngFor="let device of element.devices && element.zones.devices"// something like this

export interface Element {
    id: string;
    name: string;   
    zones: Zone[];
    devices: Device[];
}

export class Zone {
    id: string;
    name: string;
    devices: Device[];
}

export class Device {
    id: string;
    name: string;
}
Run Code Online (Sandbox Code Playgroud)

我将有权访问Element对象,因为我需要显示区域内的所有设备和设备.

javascript angular2-directives ngfor angular

0
推荐指数
1
解决办法
3354
查看次数