小编Raj*_*aja的帖子

AngularJS + JQuery:如何在angularjs中使用动态内容

我正在使用jQuery和AngularJS开发Ajax应用程序.

当我使用jQuery的html函数更新div的内容(包含AngularJS绑定)时,AngularJS绑定不起作用.

以下是我要做的代码:

$(document).ready(function() {
  $("#refreshButton").click(function() {
    $("#dynamicContent").html("<button ng-click='count = count + 1' ng-init='count=0'>Increment</button><span>count: {{count}} </span>")
  });
});
Run Code Online (Sandbox Code Playgroud)
</style><script src="http://docs.angularjs.org/angular-1.0.1.min.js"></script><style>.ng-invalid {
  border: 1px solid red;
}
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="">
  <div id='dynamicContent'>
    <button ng-click="count = count + 1" ng-init="count=0">
        Increment
      </button>
    <span>count: {{count}} </span>
  </div>


  <button id='refreshButton'>
    Refresh
  </button>
</div>
Run Code Online (Sandbox Code Playgroud)

我在带有ID的div中有动态内容#dynamicContent,并且我有一个刷新按钮,可以在单击刷新时更新此div的内容.如果我不刷新内容,增量将按预期工作,但在刷新后,AngularJS绑定将停止工作.

这可能在AngularJS中无效,但我最初使用jQuery构建应用程序并稍后开始使用AngularJS,因此我无法将所有内容迁移到AngularJS.任何有关在AngularJS中工作的帮助都非常感谢.

jquery angularjs

82
推荐指数
3
解决办法
10万
查看次数

有条件地在html头中渲染css

我试图使用角度js动态地将CSS添加到我的html头部.这是示例代码

<div ng-repeat="stylesheet in stylesheets">
        <link href="/myapp/{{stylesheet.href}}" type="{{stylesheet.type}}" rel="stylesheet" media="{{stylesheet.media}}" title="{{stylesheet.title}}" />
</div>
Run Code Online (Sandbox Code Playgroud)

此代码按预期工作,但当浏览器加载页面时,它尝试使用原始angularjs模板获取css资源,我在firebug的网络选项卡中看到"404 not found error".

Eg: request http://localhost:8080/myapp/%7B%7Bstylesheet.href%7D%7D, status 404
Run Code Online (Sandbox Code Playgroud)

当页面完全加载时,它会替换模板值并加载正确的css.

有没有办法避免404错误并使其在angularjs处理后加载css?

html css angularjs

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

Java 8扩展功能接口并将它们组合在一起

我有一个功能接口,它将标准的jdk函数扩展为泛型类型.现在我想使用andThen组合两个函数,这会抛出编译器错误

错误:(25,25)java:方法然后在接口 java.util.function.Function<T,R>中不能应用于给定的类型;
required:java.util.function.Function<? super ui.instrumentation.api.messaging.Message<R>,? extends V> found: ui.instrumentation.api.transformation.Transformer<T,R> reason:无法推断类型变量(s)V(参数不匹配; ui.instrumentation.api.transformation.Transformer<T,R>无法转换为java.util.function.Function<? super ui.instrumentation.api.messaging.Message<R>,? extends V>)

以下是示例代码:

public interface Transformer<T,R> extends Function<Message<T>, Message<R>> {

    static <T, R> Transformer<T, R> combine2(Transformer<T, R> first, Transformer<T, R> second) {
        return first.andThen(second));
    } 
}
Run Code Online (Sandbox Code Playgroud)

有没有办法组合扩展标准功能接口的功能或有更好的方法来做到这一点?

java lambda functional-programming java-8

6
推荐指数
2
解决办法
2008
查看次数

如何在Twitter Bootstrap 2.1.1中使用Affix组件

我试图通过跟踪记录的步骤在最新版本的twitter bootstrap中使用affix组件,但我无法使其工作.这是JsFiddle中的示例

我看到两个问题

  • 单击sidenav链接可正确滚动到适当的内容,但滚动内容不会使适当的sidenav链接处于活动状态
  • sidenav没有在bootstrap 网站中设置样式.

如果有人帮助我在twitter bootstrap网站上工作,我将不胜感激.

twitter-bootstrap

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

如何让打字稿方法回调在 VueJs 中工作?

我正在使用 typescript 使用 vuejs 进行开发,并面临方法回调工作的问题。我基本上是在尝试通过将数据包装在 debounce 函数中来更新我的数据。我正在使用https://www.npmjs.com/package/ts-debounce模块中的debounce 功能。下面是代码示例:

import { debounce } from 'ts-debounce';

export default Vue.extend({
    name: 'HelloWorld',
    data() {
        return {
            input: '# hello',
        };
    },

    methods: {
        updateWithDebounce: debounce(function(e: any) {
            this.input = e.target.value;
        }, 2000),

       update(e: any) {
            this.input = e.target.value;
        },
    }
Run Code Online (Sandbox Code Playgroud)

此代码在功能上有效,但因编译错误而失败:

'this' 隐式具有类型 'any',因为它没有类型注释。40 | 41 | updateWithDebounce: debounce(function(e: any) {

42 | this.input = e.target.value; | ^ 43 | }, 2000),如果有人能帮我解决这个错误,我将不胜感激。

typescript vue.js typescript-typings vuejs2

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