相关疑难解决方法(0)

如果我有jQuery背景,"在AngularJS中思考"?

假设我熟悉在jQuery中开发客户端应用程序,但现在我想开始使用AngularJS.你能描述一下必要的范式转变吗?以下是一些可能有助于您确定答案的问题:

  • 如何以不同方式构建和设计客户端Web应用程序?最大的区别是什么?
  • 我应该停止做什么/使用什么; 我应该开始做什么/使用呢?
  • 是否存在任何服务器端注意事项/限制?

我不是在寻找jQuery和之间的详细比较AngularJS.

javascript jquery angularjs

4518
推荐指数
15
解决办法
81万
查看次数

服务,指令和模块有什么区别?

我一直在阅读很多文档,而且我越来越困惑了.我基本上无法弄清楚a之间的区别

  • 服务
  • 指示
  • 模

我看到很多自定义组件.有时候他们会使用指令,有时候是服务.它始终以模块开始.有人可以用一个例子来解释这三种类型之间的区别吗?

angularjs

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

如何通过递归要求访问父指令的控制器?

我试图以递归方式到达父"box"指令的控制器:

<body ng-app="main">

<!-- no nesting: parent is the just body -->
<box></box>

<script type="text/javascript">
angular.module('main', [])
.directive('box', function() {
    return {
        restrict: 'E',
        controller: function() { },
        require: '?^box',  // find optional PARENT "box" directive
        link: function(scope, iElement, iAttrs, controller) {
            // controller should be undefined, as there is no parent box
            alert('Controller found: ' + (controller !== undefined));
        }
    };
});
</script>
</body>
Run Code Online (Sandbox Code Playgroud)

我希望控制器变量undefined在链接函数中,但我得到实际box指令的控制器.

所以我的问题是......在这种情况下如何访问PARENT控制器:

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

http://jsfiddle.net/gjv9g/1/

angularjs angularjs-directive angularjs-controller

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

AngularJS:将属性值从一个指令传递给transcluded一个

我有一种情况,我必须创建一个带有一些花里胡哨的容器指令..然后我有一个可以包装到该容器指令中的指令列表.

像这样的东西:

<the-container foo="bell" bar="whistle">

    <some-directive></some-directive>

</the-container>


<the-container foo="potato" bar="tomato">

    <some-other-directive></some-other-directive>

</the-container>
Run Code Online (Sandbox Code Playgroud)

有没有什么办法中,我可以<some-directive>和<some-other-directive>认识的foo和/或bar属性,它们在transcluded指令的价值观?

基本的theContainer指令

.directive("theContainer", function() {
    return {
        restrict: "E",
        replace: true,
        transclude: true,
        scope: true,
        templateUrl: "theContainer.html",
        compile: function(element, attrs) {
            return function(scope, element, attrs) {
                scope.containerAttrs = {
                    foo: attrs.foo,
                    bar: attrs.bar
                };
            };
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

让我们假设这两个指令一起具有不同且无关的功能

someDirective

.directive("someDirective", function() {
    return {
        restrict: "E",
        scope: true,
        templateUrl: "someDirective.html",
        controller: function($scope, $element, $attrs) {},
        compile: function(element, attrs) { …
Run Code Online (Sandbox Code Playgroud)

angularjs transclusion angularjs-directive angularjs-scope

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