我想執行初始化函數使用如下綁定屬性時,綁定後加載頁面。如何在使用模塊的angular1.5中綁定後執行函數?
function MyController(){
var my = this;
my.init = function(){
if(my.bindproperty == null)
//I'd like to set value to my.bindproperty in init function if my.bindproperty is null.
}
}
bindproperty
被綁定在組件中。
var app = angular.module('App');
app.component('myDirective', {
bindings: {
bindproperty: '='
},
controller: MyController,
templateUrl: 'path/to/view.html'
}
我試圖用ng-init()
,但它不能在此刻讀my.bindproperty
。
HTML如下所示。
<!--in parent directive-->
<div>
<my-directive bindproperty="$ctrl.parentProperty"></my-directive>
</div>
您還可以提供使用此功能的HTML代碼片段嗎? –
感謝您的評論。我添加了html代碼片段。 – wtadahiro