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();
                }
            }
        })
  • 相关阅读:
    jQuery序列化
    jQuery的ajax与django传参
    Django中的cookie与session操作
    Django文件上传
    Django表单的简单应用
    django加载模板文件
    django-admin.py创建项目失败解决方法
    django笔记
    unity创建xml与加载xml
    JavaScript相关
  • 原文地址:https://www.cnblogs.com/m110/p/8582796.html
Copyright © 2011-2022 走看看