zoukankan      html  css  js  c++  java
  • angularjs directive2

    HTML:

    <div ng-app="app">
        <food apple orange water>水果</food>
        <food apple orange>水果</food>
    </div>    

    JS:

    var app = angular.module("app", []);
        app.directive("food", function () {
            return {
                restrict: "E",
                scope: {},      //清空scope
                controller: function ($scope) {
                    $scope.foods = [];
                    this.addapple = function () { $scope.foods.push("苹果") }
                    this.addorange = function () { $scope.foods.push("橘子") }
                    this.addwater = function () { $scope.foods.push("西瓜") }
                },
                link: function (scope, element, attrs) {
                    element.bind("mouseenter", function () {
                        alert(scope.foods);
                    })
                }
            }
        })
        app.directive("apple", function () {
            return {
                require: "food",
                link: function (scope, element, attrs, ctrl) {
                    ctrl.addapple();
                }
            }
        })
        app.directive("orange", function () {
            return {
                require: "food",
                link: function (scope, element, attrs, ctrl) {
                    ctrl.addorange();
                }
            }
        })
        app.directive("water", function () {
            return {
                require: "food",
                link: function (scope, element, attrs, ctrl) {
                    ctrl.addwater();
                }
            }
        })
  • 相关阅读:
    selectHelper
    Windows Server 2003 下实现网络负载均衡(2) (转)
    顺序栈
    线性表链式存储
    线性表顺序存储
    Swift
    组件化
    swift
    Swift
    Swift
  • 原文地址:https://www.cnblogs.com/m110/p/8582796.html
Copyright © 2011-2022 走看看