简体   繁体   English

是否有一个角度指令可以限制DOM中元素的范围

[英]Is there an angular directive that can restrict scope for an element in the DOM

Hi I was just wondering if there is some built-in angular directive (ng-some-directive) that allows you to restrict the scope to a particular model for the desired DOM element. 嗨,我只是想知道是否存在一些内置的角度指令(ng-some-directive),该指令可让您将范围限制为所需DOM元素的特定模型。

I belive I have seen something similar done before, but maybe I am thinking of knockout.js 我相信我之前已经看过类似的事情,但是也许我在想剔除.js

<script>
    angular.module('example', [])
    .controller('ExampleController', ['$scope', function($scope) {
        $scope.heading = 'Some Value';
        $scope.complexModel = {...}
     }]);
</script>
<div ng-controller="ExampleController">
    <h1>{{ heading }}</h1>
    <div ng-some-directive='complexModel.to.long.really.annoying'>
        <input type='text' ng-model='variable' /> // Actually coming from complexModel.to.long.really.annoying.variable
    </div>
</div>

This is a drastically simplified version 这是大大简化的版本

Though its not meant for it 虽然这并不意味着

<div ng-init='sn = complexModel.to.long.really.annoying'>
        <input type='text' ng-model='sn' />
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM