我想从一个html指令传递参数到控制器 示例:传递参数到控制器
指令:
angular.module('app')
.directive('helloWorld', function() {
return {
replace: false,
restrict: 'AE',
templateUrl: "./views/templates/helloWorld.html"
}
});
的helloworld.html:
<body ng-app="app" >
<div ng-controller="HelloWorldCtrl">
{{ welcome }}
</div>
hello.html:
<body ng-app="app">
<hello-world/>
</body>
HelloWorldCtrl:
angular.module('app')
.controller('HomeWorldCtrl', function ($scope,) {
$scope.welcome = "Welcome"
};
})
我可以指定在hello.html的例如参数
<hello-world param="param1"/>
这是传递到控制器? 那么在HomeWorldCtrl中我可以检查参数的值吗? 有没有更好的选择来实现这一目标?
感谢,
对不起,我不明白这一点。上面的建议是否将someParam传递给控制器? –
很高兴我能帮到你 –