仅当ng-if中的条件为真时才可以调用方法吗?我有这样的重复
<div ng-repeat="i in items" ng-if="i.loc == 'abc'">
<h1>Hello.. {{getName()}}</h1>
</div>
Run Code Online (Sandbox Code Playgroud)
这是js代码
$scope.getName = function() {
console.log('fired');
return "myName";
}
Run Code Online (Sandbox Code Playgroud)
从控制台我可以看到这个方法比items.length和i.loc条件更多次.那么只有在ng-if为真时才能调用这个内部方法
我必须补充一点,我正在研究Sharepoint 2013,可视化网络部分.我的ascx:
<%@ Control Language="C#" Inherits="SharePoint.BLL.UserControls.VODCatalog, SharePoint.BLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=81fc048468441ab3" %>
<%@ Register TagPrefix="SPWP" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<div ng-app="VODCatalogModule">
<div class="wrapper" ng-view="">
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我的JS:
var VODCatalogModule = angular.module('VODCatalogModule', []);
var testWPDefinedView = 'TopLevelView';
VODCatalogModule.config(function ($routeProvider) {
$routeProvider.when('/TopLevelView', { controller: 'VODCatalogController', templateUrl: '/_catalogs/masterpage/html/VODCatalog_TopLevelView.html' })
.when('/LowLevelView', { controller: 'VODCatalogController', templateUrl: '/_catalogs/masterpage/html/VODCatalog_LowLevelView.html' })
.otherwise({ redirectTo: '/' + testWPDefinedView });
});
function VODCatalogController($scope, $http) {
$scope.VODCatalogLevel = 1;
$scope.BreadCrumbs = []; …Run Code Online (Sandbox Code Playgroud) angularjs ×2