相关疑难解决方法(0)

ng-repeat完成后调用函数

我想要实现的基本上是"on ng repeat finished rendering"处理程序.我能够检测到它何时完成,但我无法弄清楚如何从中触发一个功能.

检查小提琴:http://jsfiddle.net/paulocoelho/BsMqq/3/

JS

var module = angular.module('testApp', [])
    .directive('onFinishRender', function () {
    return {
        restrict: 'A',
        link: function (scope, element, attr) {
            if (scope.$last === true) {
                element.ready(function () {
                    console.log("calling:"+attr.onFinishRender);
                    // CALL TEST HERE!
                });
            }
        }
    }
});

function myC($scope) {
    $scope.ta = [1, 2, 3, 4, 5, 6];
    function test() {
        console.log("test executed");
    }
}
Run Code Online (Sandbox Code Playgroud)

HTML

<div ng-app="testApp" ng-controller="myC">
    <p ng-repeat="t in ta" on-finish-render="test()">{{t}}</p>
</div>
Run Code Online (Sandbox Code Playgroud)

答案:来自finishmove的工作小提琴:http …

events directive handler ready angularjs

250
推荐指数
5
解决办法
14万
查看次数

Angularjs - 将参数传递给指令

我想知道是否有办法将参数传递给指令?

我想要做的是从控制器附加一个指令,如下所示:

$scope.title = "title";
$scope.title2 = "title2";

angular.element(document.getElementById('wrapper')).append('<directive_name></directive_name>');
Run Code Online (Sandbox Code Playgroud)

是否可以同时传递参数,以便我的指令模板的内容可以链接到一个或另一个范围?

这是指令:

app.directive("directive_name", function(){
    return {
        restrict:'E',
        transclude:true,
        template:'<div class="title"><h2>{{title}}</h3></div>',
        replace:true
    };
})
Run Code Online (Sandbox Code Playgroud)

如果我想使用相同的指令但使用$ scope.title2会怎么样?

arguments controller directive angularjs

62
推荐指数
4
解决办法
14万
查看次数

Angularjs指令:隔离范围和attrs

请看这里的例子

foodMeApp.directive('fmRating', function() {
  return {
    restrict: 'E',
    scope: {
      symbol: '@',
      max: '@',
      readonly: '@'
    },
    require: 'ngModel',
    link: function(scope, element, attrs, ngModel) {

      attrs.max = scope.max = parseInt(scope.max || 5, 10);
...
Run Code Online (Sandbox Code Playgroud)

角需要symbol,max,readonly以在所述分离的范围对象从父范围访问它来限定.

在这里使用

<fm-rating ng-model="$parent.restaurant.price" symbol="$" readonly="true"></fm-rating>

那么,目的是attrs什么?无法访问所有传递的属性attrs.为什么不能访问max的值attrs.max而不是scope.max

为什么要分配回来attrs.max = scope.max

由于这个应用程序是由Angular作者编写的,我希望有一个理由.

谢谢.

javascript angularjs

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