作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何更改指令的范围值?我已经尝试过这种方式:
在模板中:
<h1>{{abcd}}</h1>
<example-directive abcd="abcd"></example-directive>
在指令中
..
scope: {
abcd: '='
},
link: function($scope){
$scope.abcd = "change it pleeease";
}
....
但结果我什么也没得到。所以“h1”标签是空的......有人知道为什么吗?
指令:
(function(){
'use strict';
var standingsDirective = function(api, $http){
return {
restrict: 'E',
scope : {
sid: '=',
loadingstatus: '='
},
templateUrl: "teams/views/standings.html",
link: function(scope){
scope.loadingstatus = "loading";
$http.get(api+'/getsomething'+scope.id).success(function(result){
scope.data = result;
if(scope.data && scope.data.length > 0){
scope.loadingstatus = "loaded";
}else{
scope.loadingstatus = "notloaded";
}
}).error(function(){
scope.loadingstatus = "notloaded";
});
}
};
};
var teamsModule = angular.module('app.teams');
teamsModule.directive('standings', ['api', '$http', standingsDirective]);
}());
模板文件:
...
<a ng-show="loadingstatus == 'loaded'" ng-click="subview='standing'" class="activeLink">standings - {{loadingstatus}}</a>
...
<standings sid="sid" loadingstatus="loadingstatus" ng-show="subview=='standing'"></standings>
...
最佳答案
回答我的问题:
首先,非常感谢“Fedaykin”帮助我提出评论。他是那个指出它应该有效的人,因此问题应该出在我代码的另一部分。
发现 ng-if 属性阻止了我的指令的执行。html 代码如下所示:
<a ng-show="loadingstatus == 'loaded'" ng-click="subview='standing'" class="activeLink">standings - {{loadingstatus}}</a>
<div ng-if="subview=='standing'">
...
<standings sid="sid" loadingstatus="loadingstatus" ng-show=" subview=='standing'"> </standings>
....
</div>
所以这导致了这种奇怪的行为。我希望这篇文章能够帮助其他有类似问题的人解决问题。
关于AngularJS : How to change scope value from isolated scope within directive,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27806699/
我是一名优秀的程序员,十分优秀!