我是角度js的新手,目前仍然坚持使用非常有线的bug.控制器中的函数在通过路径加载的视图调用时运行两次.
你会看到警报两次!!
我的观点很简单
我的应用程序代码如下
var IB = angular.module('IB', []);
//channel controller
IB.controller('channelsController', function ($scope, $routeParams) {
$scope.greet = function () {
alert('hi');
};
});
IB.config(function ($routeProvider) {
$routeProvider
.when('/channels', {
controller: 'channelsController',
template: '{{greet()}}'
})
.otherwise({ redirectTo: '/channels' });
});
Run Code Online (Sandbox Code Playgroud) 当*ngIf满足某些条件时,如何从类装饰器调用某个方法.我有一个完全像AngularJS问题的场景,其中使用ng-init()但ng-init不是Angular2的一部分
<div *ngIf="obj.someProperty" callSomeMethod() >
<!--render inner parts-->
</div>
Run Code Online (Sandbox Code Playgroud)