- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我打算在具有不同 Controller 的多个 View 中使用一个模板。
但现在我意识到我不能只在模板中编写通用绑定(bind),因为值将放在 $scope.concreteControllerName
中。 .
ngInclude 的 Angular 文档比如说
This directive creates new scope.
ng-init
指令并将 Controller 实例传递给模板的范围:
<ng-include src="..." ng-init="controller=concreteControllerName"/>
<ng-include src="..." ng-init="model=getModelForTemplate()"/>
{{controller.boundvalue}}
在模板中。
最佳答案
使用约翰爸爸的 controllerAs View Syntax和 controllerAs with vm .您在 ng-include
中指定不同的 Controller 指令,但使用相同的 src html 模板。常见vm
变量名在模板中使用。
index.html
<div ng-include ng-controller="controllerOne as vm" src="'same.html'"></div>
<div ng-include ng-controller="controllerTwo as vm" src="'same.html'"></div>
<div ng-include ng-controller="controllerThree as vm" src="'same.html'"></div>
function controllerOne() {
var vm = this;
vm.name = 'Controller One!';
<div>{{vm.name}}</div>
关于angularjs - 将 ngInclude 与 ControllerAs 语法结合使用的最佳实践是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26427950/
我使用 plunker 中的范围创建了一个 d3 条形图指令 http://plnkr.co/edit/yF8H9i8tyu1o2xJCN9bV Controller 的范围内有 chartData。
我正在编写 AngularJS 教程,我看到以下代码: .state('index',{ url:"/", templateUrl:"views/index.html", controll
我正在尝试遵循 John Papa 的 angularJS 风格指南 here并开始将我的指令切换为使用 controllerAs。但是,这是行不通的。我的模板似乎无法访问分配给 vm 的任何内容。请
我是 Angular 新手,想使用 ui-bootstrap 来使用模态(弹出表单)来自 Angular 。我正在学习Angular bootstrap site 。可以看出,它利用了Controll
我有几个嵌套指令。我试图保持一致并使用 controllerAs 语法。但是我正在努力寻找一种干净的方法让 children 调用父方法,该方法不包括父方法在其范围内放置看似随机的函数。 angula
我需要的是根据通过 HTML 元素属性值传递给该指令的值将数据注入(inject)指令内,该元素动态变化. 这是我的代码: angular.module('test', []) .contro
据我所知,在“指令定义对象”上使用 Controller 属性会在每次链接给定指令时创建该 Controller 的单独实例吗? 现在玩 controllerAs patterns 我可以看到,当每个
在 AngularJS 中使用 controllerAs 语法时,为 ng-click 等定义处理程序的最佳位置是什么?在 Controller 上还是在作用域上(在链接函数中定义)? 那么,你使用:
我实际上正在创建一个小指令,但我正面临范围对象和 controllAs 的问题。 事实上,我有这样的结果: angular.module('app') .directive('historyConne
我的网络应用程序有几个页面,它们都有自己的 Controller 。在这些页面中,我使用也有 Controller 的指令。所有 Controller 都使用 controllerAs 语法,它们都设
我目前有一个使用父 Controller 范围内属性的指令: .controller('MainCtrl', function($scope) { $scope.name = 'My Name';
我无法使用 controllerAs 语法/样式从这里访问指令的独立作用域变量。 我可以使用 $scope 访问变量,但这似乎并不一致。有没有办法使用 this 访问隔离作用域的变量? 这是一个 gi
最近我一直在使用 ControllerAs 语法,但我不确定如何能够在 $watch 中从 Controller 更改模型。 我的 watch 是这样的: $scope.$watch(angular.
嘿,我是 angularjs 的新手,我在 angularjs 中使用 controlleras 样式,因为代码是可呈现的和网络的。我的问题是在 Controller 中调用子函数我的代码如下 //
有人告诉我,controllerAs 模式通过在作用域上附加更少的东西来提高 AngularJS 应用程序的性能。 我真的不明白这是怎么发生的,因为 Controller 本身在范围内公开了它的属性。
我在 html 代码中有这个: {{ ::schema.name }} Empty 问题是,使用此语法时我看不到任何结果 - 如果未填充过滤器,则应显示 10 个结果。 注意:
正如标题所示,我在使用嵌套自定义指令的 Angular 项目上遇到了一些问题。我正在创建一个界面,允许用户通过单击复选框来过滤搜索结果的 JSON 提要。指令模板层次结构如下: 我似乎能
这是我的代码: //HTML {{foo.name}} //脚本 app.directive('myDirective', function() { return { restr
我使用 controllerAs 语法来避免在我的 Controller 中出现 $scope soup,并且还使用 ui.bootstrap 来呈现模态视图。 我需要打开一个与当前 Controll
嗨,我有 StudentController如下, function StudentController($scope,StudentService){ $scope.student = St
我是一名优秀的程序员,十分优秀!