背景图像没有出现在AngularJS中

时间:2016-04-11 04:34:18

标签: javascript html css angularjs background-image

我的自定义背景图片未显示在AngularJS中。无法弄清楚原因。

当我在控制台中测试@Configuration @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true) public class SecurityConfiguration extends WebSecurityConfigurerAdapter { @Inject public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { auth.authenticationProvider(customAuthenticationProvider) auth.userDetailsService(customUserDetailsService) .passwordEncoder(passwordEncoder()); } @Override public void configure(WebSecurity web) throws Exception { web.ignoring() .antMatchers("/scripts/**/*.{js,html}") .antMatchers("/bower_components/**") .antMatchers("/i18n/**") .antMatchers("/assets/**") .antMatchers("/swagger-ui.html") .antMatchers("/test/**"); } } 时,我得到了对象$scope.setBackground

控制器:

{background-image: "url(image.jpg)"}

HTML:

app.controller('backgroundImageCtrl', function($scope, $http) {
    $scope.setBackground = {
        'background-image' : 'url(image.jpg)'
    };
})

1 个答案:

答案 0 :(得分:1)

@Mosh Feu建议的简单解决方案,只需将ng-controller="backgroundImageCtrl"ng-style="setBackground"放在内部div中

<script type = "text/ng-template" id="/page.html">
    <div ng-controller="backgroundImageCtrl" ng-style="setBackground">
    ...
    </div>
</script>